Skip to content

Accept uuid.UUID objects in UUID validator - #769

Merged
azmeuk merged 8 commits into
pallets-eco:mainfrom
TurnrDev:patch-1
May 6, 2026
Merged

azmeuk merged 8 commits into
pallets-eco:mainfrom
TurnrDev:patch-1

Conversation

@TurnrDev

@TurnrDev TurnrDev commented Feb 9, 2023

Copy link
Copy Markdown
Contributor

Fixes #549 and pallets-eco/flask-admin#1444

Better implementation of #609

Also, account for uuid.UUID raising TypeErrors
@TurnrDev
TurnrDev marked this pull request as ready for review February 9, 2023 16:28
@TurnrDev
TurnrDev marked this pull request as draft February 9, 2023 16:37
@TurnrDev
TurnrDev marked this pull request as ready for review February 9, 2023 16:42
@TurnrDev

TurnrDev commented Feb 9, 2023

Copy link
Copy Markdown
Contributor Author

Test Result:

================================================= test session starts =================================================
platform win32 -- Python 3.10.2, pytest-7.2.1, pluggy-1.0.0 -- C:\Users\JayTurner\.virtualenvs\wtforms-V-P53RkO\Scripts\python.exe
cachedir: .pytest_cache
rootdir: C:\Users\JayTurner\Personal\wtforms, configfile: setup.cfg
collected 7 items

tests/validators/test_uuid.py::test_valid_uuid_passes[2bc1c94f-0deb-43e9-92a1-4775189ec9f8] PASSED               [ 14%]
tests/validators/test_uuid.py::test_valid_uuid_passes[2bc1c94f0deb43e992a14775189ec9f8] PASSED                   [ 28%]
tests/validators/test_uuid.py::test_valid_uuid_passes[uuid_val2] PASSED                                          [ 42%]
tests/validators/test_uuid.py::test_bad_uuid_raises[2bc1c94f-deb-43e9-92a1-4775189ec9f8] PASSED                  [ 57%]
tests/validators/test_uuid.py::test_bad_uuid_raises[2bc1c94f-0deb-43e9-92a1-4775189ec9f] PASSED                  [ 71%]
tests/validators/test_uuid.py::test_bad_uuid_raises[gbc1c94f-0deb-43e9-92a1-4775189ec9f8] PASSED                 [ 85%]
tests/validators/test_uuid.py::test_bad_uuid_raises[2bc1c94f 0deb-43e9-92a1-4775189ec9f8] PASSED                 [100%]

================================================== 7 passed in 0.02s ==================================================

@TurnrDev

Copy link
Copy Markdown
Contributor Author

I have reformted the imports on re the tox style checks and added a changelog entry

@azmeuk azmeuk added the enhancement New feature, or existing feature improvement label Jul 22, 2023
@azmeuk

azmeuk commented Oct 9, 2023 •

Copy link
Copy Markdown
Member

Hi @TurnrDev
I was thinking about this PR and I was wondering: if the validator gets UUID objects in the end, that means that it has been initialized (with model data for instance), and it has been validated without formdata (else the formdata would have been validated, and formdata can only be strings). Out of curiosity, why do you validate your model data?

@TurnrDev

TurnrDev commented Oct 9, 2023

Copy link
Copy Markdown
Contributor Author

Hi @azmeuk

I encoured this issue when using flask-admin with sqlalchemy. I can't say for sure why they're doing what they're doing.

@azmeuk

azmeuk commented May 6, 2026

Copy link
Copy Markdown
Member

#662 talks about how wtforms should handle native Python types. One day we will do this properly, in the meantime this fix is cheap enough.

@azmeuk
azmeuk merged commit c2c0714 into pallets-eco:main May 6, 2026
17 checks passed
@TurnrDev

TurnrDev commented May 6, 2026

Copy link
Copy Markdown
Contributor Author

Woah! I lost all hope on this! Have a lovely week! Let me know if any issues arise from this

@TurnrDev
TurnrDev deleted the patch-1 branch May 6, 2026 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature, or existing feature improvement

Development

Successfully merging this pull request may close these issues.

UUID validator fails if field.data is a UUID object instead of str

2 participants