Skip to content

add default coerce to any Select2Field#2784

Open
samialfattani wants to merge 1 commit into
pallets-eco:masterfrom
samialfattani:fix/coerce
Open

add default coerce to any Select2Field#2784
samialfattani wants to merge 1 commit 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

ElLorans commented Feb 7, 2026

Copy link
Copy Markdown
Contributor

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

ElLorans commented Feb 8, 2026

Copy link
Copy Markdown
Contributor

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

samialfattani commented Apr 27, 2026

Copy link
Copy Markdown
Contributor Author

it is ready for review now, if it is hard to review because of many commits please let me know so i may squash them into a new PR and close this one

include all field types and cover all default end explicit coerce
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