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
UUIDv7 is great. It's lexicographically sortable, and the prefix means I can distinguish one ID from another and have a created timestamp without storing extra information in the db. So the idea is that the API returns IDs such as org_BwFJbmSZpBC3YZXUm3jjG, instead of 0186de4c-f634-7baa-9a1f-d77dbe2296eb.
But when I give a model with that field to python, I get this pydantic error:
1 validation error for TokenSchema
user -> organizations -> 0 -> id
value is not a valid uuid (type=type_error.uuid)
Traceback (most recent call last):
File "/home/adys/.cache/pypoetry/virtualenvs/financica-AU4l5g1E-py3.10/lib/python3.10/site-packages/ninja/operation.py", line 104, in run
result =self.view_func(request, **values)
File "/home/adys/src/financica/backend/financica/api/auth.py", line 31, in obtain_tokenreturn TokenSchema(token=token.secret, user=token.user)
File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__pydantic.error_wrappers.ValidationError: 1 validation error for TokenSchema
user -> organizations -> 0 -> id
value is not a valid uuid (type=type_error.uuid)
1 validation error for TokenSchema
user -> organizations -> 0 -> id
value is not a valid uuid (type=type_error.uuid)
Traceback (most recent call last):
File "/home/adys/.cache/pypoetry/virtualenvs/financica-AU4l5g1E-py3.10/lib/python3.10/site-packages/ninja/operation.py", line 104, in run
result =self.view_func(request, **values)
File "/home/adys/src/financica/backend/financica/api/auth.py", line 31, in obtain_tokenreturn TokenSchema(token=token.secret, user=token.user)
File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__pydantic.error_wrappers.ValidationError: 1 validation error for TokenSchema
user -> organizations -> 0 -> id
value is not a valid uuid (type=type_error.uuid)
Ideally, Django Ninja should be able to tell what the actual type should be, thanks to the from_db_value type hint. Failing that, is there an easier way to hint at ModelSchema what the type is supposed to be, that doesn't involve adding a custom field everywhere it's missing?
The text was updated successfully, but these errors were encountered:
I use prefixed UUIDv7 as ID fields in my database. The field looks like this:
UUIDv7 is great. It's lexicographically sortable, and the prefix means I can distinguish one ID from another and have a created timestamp without storing extra information in the db. So the idea is that the API returns IDs such as
org_BwFJbmSZpBC3YZXUm3jjG
, instead of0186de4c-f634-7baa-9a1f-d77dbe2296eb
.But when I give a model with that field to python, I get this pydantic error:
Ideally, Django Ninja should be able to tell what the actual type should be, thanks to the
from_db_value
type hint. Failing that, is there an easier way to hint at ModelSchema what the type is supposed to be, that doesn't involve adding a custom field everywhere it's missing?The text was updated successfully, but these errors were encountered: