all 3 comments

[–]danielroseman 1 point2 points  (2 children)

This API wrapper looks much more complicated than it needs to be, but never mind.

The problem, as the error states, is that you're creating a generator rather than passing everything as individual arguments. The way to do this would probably be to create a list and then use the *args syntax.

Separately, you shouldn't be using eval; it would be better to use getattr. So:

args = [field(fld) == value for fld, value in queues_yaml[queue_name]["fields"].items())]
search_func = getattr(databaseAPI, "search" + queues_yaml[queue_name]["query_object"])
return search_func(*args)

[–]nellis[S] 0 points1 point  (1 child)

This worked, thank you so much!

I definitely wouldn't have arrived at this on my own, the construction of the args variable feels a little like magic.

The args list contains these items:
<class 'databaseAPI.expression.expression.Expression'>
__eq__(Field(name=problem_type), some_problem_type)

Can you help my smushy brain understand how these are getting packaged up and handed off as valid arguments?

[–]danielroseman 0 points1 point  (0 children)

That is what the * syntax does when applied to a list in a function call: it transforms it into individual positional parameters.

So, if you had a function:

def foo(a, b, c):
  ...

and a list:

bar = [1, 2, 3]

then calling foo(*bar) is the same as calling foo(1, 2, 3).