Skip to content

Commit

Permalink
bugfix: _select_args should not return [None]
Browse files Browse the repository at this point in the history
_select_args would return [None] because 'select' was present in
req.state but with a value of None.

Also runtime check returned values, because the typing of req.args is
very lax at the moment.
  • Loading branch information
fredrikt committed May 3, 2021
1 parent cbbdce4 commit 4f4df74
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/pyff/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,18 +685,26 @@ def load(req: Plumbing.Request, *opts):
req.md.rm.reload(fail_on_error=bool(_opts['fail_on_error']))


def _select_args(req):
def _select_args(req: Plumbing.Request) -> List[str]:
log.debug(f'Select args: {req.args}, state: {req.state}')
args = req.args
if args is None and 'select' in req.state:
args = [req.state.get('select')]
if args is None and req.state.select:
args = [req.state.select]
log.debug(f'Using req.state.select: {args}')
if args is None:
args = req.store.collections()
log.debug(f'Using req.store.collections: {args}')
if args is None or not args:
args = req.store.lookup('entities')
log.debug(f'Using req.store.entities: {args}')
if args is None or not args:
args = []

log.info("selecting using args: %s" % args)
log.info(f'selecting using args: {args}')

for this in args:
if not isinstance(this, str):
raise ValueError(f'Selection resulted in something that is not a string: {this}')

return args

Expand Down

0 comments on commit 4f4df74

Please sign in to comment.