Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Support YDB native UUID type #86

wants to merge 1 commit into from

Conversation

vgvoleg
Copy link
Collaborator

@vgvoleg vgvoleg commented Jul 15, 2025

Closes: #84

@vgvoleg vgvoleg requested a review from Copilot July 15, 2025 14:37
Copy link

@Copilot Copilot AI left a 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 of uuid.UUID and string values into a native UUID column.
  • Extend the SQL generation and YDB type mapping to recognize UUID and map it to ydb.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 a ValueError 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):

Comment on lines +26 to +28
import uuid as uuid_module

value = uuid_module.UUID(value)
Copy link
Preview

Copilot AI Jul 15, 2025

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.

Suggested change
import uuid as uuid_module
value = uuid_module.UUID(value)
value = uuid.UUID(value)

Copilot uses AI. Check for mistakes.

Comment on lines +36 to +38
return None


Copy link
Preview

Copilot AI Jul 15, 2025

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.

Suggested change
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to use native UUID insted of utf-8 uuid in ydb-sqlalchemy
1 participant