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
The current implementation of UUID validator at https://github.com/wtforms/wtforms/blob/master/src/wtforms/validators.py#L520 assumes that field.data is of type str. However, if field.data is already an instance of uuid.UUID the validator fails with the following exception: AttributeError: 'UUID' object has no attribute 'replace'.
I've found this issue working with PostgreSQL, SQLAlchemy and using Flask-Admin with a field declared as:
fromsqlalchemy.dialects.postgresqlimportUUIDimportsqlalchemyassa# ... More code hereuuid=db.Column(
UUID(as_uuid=True), nullable=False, default=uuid4,
server_default=sa.text('uuid_generate_v4()'), index=True)
Thank you for reporting this issue.
The patch you propose seems pretty simple, would you submit a pull-request for that? If you do, do not forget to provide a unit test.
The current implementation of
UUID
validator at https://github.com/wtforms/wtforms/blob/master/src/wtforms/validators.py#L520 assumes that field.data is of typestr
. However,if field.data
is already an instance ofuuid.UUID
the validator fails with the following exception:AttributeError: 'UUID' object has no attribute 'replace'
.I've found this issue working with PostgreSQL, SQLAlchemy and using Flask-Admin with a field declared as:
Note the use of
as_uuid=True
as said at pallets-eco/flask-admin#1444.My proposal is to change this line
uuid.UUID(field.data)
byuuid.UUID(str(field.data))
, this way it should work in both cases.Meanwhile, I've done the following workaround implementing a new UUID validator overriding the
__call__()
method as follows:The text was updated successfully, but these errors were encountered: