-
Notifications
You must be signed in to change notification settings - Fork 301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
uuid.UUID
or str
in SQLAlchemy models
#6743
Comments
To avoid any misunderstanding, this is what the type hints claim we are using. As far as I can tell, we are not.
I’m not sure if this particular comment is relevant because we do not store UUIDs as strings in the database.
At some point, we will have to convert this to a string (e.g. in the gateway or REST layer). |
Thanks for the correction on the first point, I updated the main post.
Good point. I mistakenly conflated using
The |
Do I understand correctly that you are suggesting replacing our own rse_id: Mapped[str] = mapped_column(Uuid(as_uuid=False)) |
Yeah, I think it might be better in the long run to move to their version of and the |
This is a follow-up from this PR comment: #6497 (comment), where it was suggested to change all instances of
Mapped[uuid.UUID]
toMapped[str]
.uuid.UUID
This is the Python-implemented
UUID
type: https://docs.python.org/3/library/uuid.html#uuid.UUID, which is the type hint we're currently using, e.g.:rucio/lib/rucio/db/sqla/models.py
Lines 1443 to 1444 in 2c389be
str
There is this SO answer where this is discussed https://stackoverflow.com/a/41434923, and there are a couple comments that mention some downsides to storing UUIDs as strings:
sqlalchemy.types.Uuid
As an alternative to both
uuid.UUID
andstr
, there is the SQLA2.0Uuid
type: https://docs.sqlalchemy.org/en/20/core/type_basics.html#sqlalchemy.types.UuidThis seems to be a similar implementation to the
GUID
type we're currently using:rucio/lib/rucio/db/sqla/types.py
Lines 28 to 51 in 2c389be
See also this SO answer: https://stackoverflow.com/a/76059829
To do
I think
sqlalchemy.types.Uuid
seems to be the appropriate type to use in this context. However, I think it might be worth investigating this a bit further before we commit to a specifc type.The text was updated successfully, but these errors were encountered: