Skip to content

add default coerce to any Select2Field#2784

Open
samialfattani wants to merge 12 commits into
pallets-eco:masterfrom
samialfattani:fix/coerce
Open

add default coerce to any Select2Field#2784
samialfattani wants to merge 12 commits into
pallets-eco:masterfrom
samialfattani:fix/coerce

Conversation

@samialfattani
Copy link
Copy Markdown
Contributor

run-time error is raised if Select2Field did'nt include coerce=int in form_args

Here is how to replicate the error

  class Model2(db.Model):  
      def __init__(self,int_field=None):
          self.int_field = int_field

      int_field = Column(Integer)

  class MyModelView(ModelView):
      form_columns = ["int_field"]
      form_choices = {"int_field": [("101", "101"), ("150", "150")]}
      form_args = {
          "int_field": {"validators": [NumberRange(min=100, max=199)]},
      }

This PR adds a default coerce function if it is not provided explicitly based on the Column's type

the added tests won't pass without changes in this PR

@ElLorans
Copy link
Copy Markdown
Contributor

ElLorans commented Feb 7, 2026

Why do you need to change typing? Do we need to change all other orm libraries?

@samialfattani
Copy link
Copy Markdown
Contributor Author

Why do you need to change typing? Do we need to change all other orm libraries?

what do you mean? i'm not changing the typing. This PR just extract the right coerce function that match the Column's type.

Comment thread flask_admin/_types.py
@ElLorans
Copy link
Copy Markdown
Contributor

ElLorans commented Feb 8, 2026

Sorry, let me be more specific. Why not editing T_FIELD_ARGS_VALIDATORS_ALLOW_BLANK

@samialfattani
Copy link
Copy Markdown
Contributor Author

Sorry, let me be more specific. Why not editing T_FIELD_ARGS_VALIDATORS_ALLOW_BLANK

the T_FIELD_ARGS_VALIDATORS_ALLOW_BLANK is being used in other 2 functions _get_description and _convert_relation and i don't want those funcitons to be harmed if just edit it. but any i can have a try if you say so.

Comment thread flask_admin/contrib/sqla/form.py
@samialfattani samialfattani marked this pull request as ready for review March 28, 2026 11:24
@samialfattani
Copy link
Copy Markdown
Contributor Author

it is ready for review now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants