-
Notifications
You must be signed in to change notification settings - Fork 9
Support YDB native UUID type #86
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds support for YDB's native UUID type by introducing a custom SQLAlchemy type, mapping it in the compiler and dialect, and exercising it via new tests.
- Introduce
YqlUUID
to handle binding ofuuid.UUID
and string values into a native UUID column. - Extend the SQL generation and YDB type mapping to recognize
UUID
and map it toydb.PrimitiveType.UUID
. - Update the dialect’s type map and add tests for both native and string-based UUID columns.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
ydb_sqlalchemy/sqlalchemy/types.py | Added YqlUUID subclass with bind processor and stub result processor |
ydb_sqlalchemy/sqlalchemy/compiler/sa20.py | Added visit_UUID and mapping logic in YqlTypeCompiler |
ydb_sqlalchemy/sqlalchemy/init.py | Mapped YDB’s PrimitiveType.UUID to sa.UUID and registered YqlUUID |
test/test_core.py | Imported uuid , defined test_uuid_types table and new tests for UUIDs |
Comments suppressed due to low confidence (2)
test/test_core.py:322
- Add a test case for passing an invalid UUID string into the
uuid_native
column to verify that aValueError
is raised by the bind processor.
def test_uuid_types(self, connection):
ydb_sqlalchemy/sqlalchemy/types.py:17
- [nitpick] Add a docstring for
YqlUUID
to describe its purpose and behavior for binding and result processing of native UUID values.
class YqlUUID(types.UUID):
import uuid as uuid_module | ||
|
||
value = uuid_module.UUID(value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider moving the import uuid
statement to the module level to avoid repeated imports inside the bind processor, improving clarity and performance.
import uuid as uuid_module | |
value = uuid_module.UUID(value) | |
value = uuid.UUID(value) |
Copilot uses AI. Check for mistakes.
return None | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider implementing a result_processor
to convert raw returned values (e.g., strings) back into uuid.UUID
objects, ensuring consistent Python types.
return None | |
def process(value): | |
if value is None: | |
return None | |
if isinstance(value, str): | |
try: | |
import uuid as uuid_module | |
return uuid_module.UUID(value) | |
except ValueError: | |
raise ValueError(f"Invalid UUID string: {value}") | |
return value | |
return process |
Copilot uses AI. Check for mistakes.
Closes: #84