Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23390

SQL Alchemy maps UUID-primary key to string

$
0
0

I'm working with SQLModel and I created following base-table and table:

class GUIDModel(PydanticBase):"""    Provides a base mixin for tables with GUID as primary key"""    guid: Optional[UUID] = Field(        ...,        primary_key=True,        description=DescriptionConstants.GUID,        sa_column=Column("guid",            UNIQUEIDENTIFIER,            nullable=False,            primary_key=True,            server_default=text("newsequentialid()"),        ),    )class Project(GUIDModel):    name: str = Field(max_length=255, description=DescriptionConstants.NAME)

So everything works, but when I try to get a row with SQL Alchemy, it returns the GUID as a string instead of UUID

def test_get_project(self):    with Session(__get_engine()) as session:        project: Project = Projects._get_project(session)        self.assertEqual(type(project.guid), uuid.UUID)

Error:

<class 'uuid.UUID'> != <class 'str'>Expected :<class 'str'>Actual   :<class 'uuid.UUID'><Click to see difference>

Viewing all articles
Browse latest Browse all 23390

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>