Snowflake-Labs / django-snowflake

MIT License
59 stars 15 forks source link

UUIDs being stripped of hyphens #41

Closed chrislondon closed 2 years ago

chrislondon commented 2 years ago

We use UUIDs as our primary key and django-snowflake seems to be stripping out the hyphens making it unusable.

What I'm seeing:

>>> Customer.objects.filter(company_id='8e0694de-8d2d-4ffd-8cef-76e9a06ac650').count()
...
2022-01-26 16:47:37,209 snowflake.connector.connection DEBUG    parameters: ("'8e0694de8d2d4ffd8cef76e9a06ac650'",)
...
0

What I expect to see:

>>> Customer.objects.filter(company_id='8e0694de-8d2d-4ffd-8cef-76e9a06ac650').count()
...
2022-01-26 16:47:37,209 snowflake.connector.connection DEBUG    parameters: ("'8e0694de-8d2d-4ffd-8cef-76e9a06ac650'",)
...
1809519

I believe this is in django-snowflake and not in the snowflake connector because I can run this just fine:

>>> with con.cursor() as cur:
...     cur.execute("select count(*) from customers where company_id=%s", ['8e0694de-8d2d-4ffd-8cef-76e9a06ac650'])
...     print(cur.fetchone())
...
2022-01-26 16:45:57,240 snowflake.connector.connection DEBUG    parameters: ("'8e0694de-8d2d-4ffd-8cef-76e9a06ac650'",)
...
(1809519,)
chrislondon commented 2 years ago

My apologies. It looks like this is the behavior of the Django model UUIDField:

class UUIDField(Field):
    # ... 

    def get_db_prep_value(self, value, connection, prepared=False):
        if value is None:
            return None
        if not isinstance(value, uuid.UUID):
            value = self.to_python(value)

        if connection.features.has_native_uuid_field:
            return value
        return value.hex