You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the example below, assuming parent is a many-to-one field that maps to a QuerySelectField, The query_factory's callable (get_all_except_first) will not be used, it just returns all records of the model. On the other hand, using a normal form works as expected.
defget_all_except_first():
returnExample.query.filter(Example.id!=1)
# This doesn't workExampleForm=model_form(
Example,
field_args={
"parent": {"query_factory": get_all_except_first}
...
}
...
)
# This worksclassExampleForm(FlaskForm):
parent=QuerySelectField(query_factory=get_all_except_first)
...
Failed debugging attempts
Got confused when attempting to debug code similar to the example above (using model_form):
Printing field_args in the conv_ManyToOne method shows that query_factory points to <function ModelConverterBase.convert.<locals>.<lambda> at 0x1076a3b80>.
Using the debugger to inspect field_args in the conv_ManyToOne method shows that it doesn't contain query_factory
Background
In the example below, assuming
parent
is a many-to-one field that maps to aQuerySelectField
, Thequery_factory
's callable (get_all_except_first
) will not be used, it just returns all records of the model. On the other hand, using a normal form works as expected.Failed debugging attempts
Got confused when attempting to debug code similar to the example above (using
model_form
):field_args
in theconv_ManyToOne
method shows thatquery_factory
points to<function ModelConverterBase.convert.<locals>.<lambda> at 0x1076a3b80>
.field_args
in theconv_ManyToOne
method shows that it doesn't containquery_factory
https://github.com/wtforms/wtforms-sqlalchemy/blob/9884ab82ffd51a14dc2778468d428985d4c8e26b/wtforms_sqlalchemy/orm.py#L232-L234
The text was updated successfully, but these errors were encountered: