Package: django-snowflake
Snowflake backend for DjangoInstall and usageUse the version of django-snowflake that corresponds to your version of
Django. For example, to get the latest compatible release for Django 5.0.x:pip install django-snowflake==5.0.*The minor release number of Django doesn't correspond to the minor release
number of django-snowflake. Use the latest minor release of each.Configure the DjangoDATABASESsetting similar to this:DATABASES={'default':{'ENGINE':'django_snowflake','NAME':'MY_DATABASE','SCHEMA':'MY_SCHEMA','WAREHOUSE':'MY_WAREHOUSE','USER':'my_user','PASSWORD':'my_password','ACCOUNT':'my_account',# Include 'OPTIONS' if you need to specify any other# snowflake.connector.connect() parameters, documented at:# https://docs.snowflake.com/en/user-guide/python-connector-api.html#connect'OPTIONS':{# Examples:'role':'MY_ROLE',# To use native Okta authenticators:# https://docs.snowflake.com/en/user-guide/admin-security-fed-auth-use#native-sso-okta-only'authenticator':'https://example.okta.com',# To use private key authentication:'private_key_file':'<path>/rsa_key.p8','private_key_file_pwd':'my_passphrase',},},}Persistent connectionsTo use persisent connections, set Django'sCONN_MAX_AGEand Snowflake Python Connector'sclient_session_keep_alive:DATABASES={'default':{# ...'CONN_MAX_AGE':None,'OPTIONS':{'client_session_keep_alive':True,},},}Notes on Django fieldsConsistent withSnowflake's convention,
this backend uppercases all database identifiers (table names, column names,
etc.) unless they are quoted, e.g.db_table='"table_name"'.Snowflake supports defining foreign key and unique constraints, however, it
doesn't enforce them. Thus, Django manages these constraints andinspectdbdetects them, but Django won't raiseIntegrityErrorif they're violated.Snowflake doesn't support indexes. Thus, Django ignores any indexes defined
on models or fields.Snowflake doesn't support check constraints, so the variousPositiveIntegerFieldmodel fields allow negative values (though validation
at the form level still works).Notes on Django QuerySetsSnowflake haslimited support for subqueries.Valid values forQuerySet.explain()'sformatparameter are'json','tabular', and'text'. The default is'tabular'.Known issues and limitationsThis list isn't exhaustive. If you run into a problem, consultdjango_snowflake/features.pyto see if a similar test is skipped. Pleasecreate an issue on GitHubif you encounter an issue worth documenting.Snowflake doesn't supportlast_insert_idto retrieve the ID of a newly
created object. Instead, this backend issues the querySELECT MAX(pk_name) FROM table_nameto retrieve the ID. This is subject
to race conditions if objects are created concurrently. This makes this
backend inappropriate for use in web app use cases where multiple clients
could be creating objects at the same time. Further, you should not manually
specify an ID (e.g.MyModel(id=1)) when creating an object.Snowflake only supports single layer transactions, but Django'sTestCaserequires that the database supports nested transactions. Therefore, Django'sTestCaseoperates likeTransactionTestCase, without the benefit of
transactions to speed it up. Starting in Django 5.1,TestCaseuses
Snowflake's single layer transaction support to give some speed up.Due to snowflake-connector-python'slack of VARIANT support,
someJSONFieldqueries with complex JSON parametersdon't work.For example, ifvalueis aJSONField, this won't work:>>>JSONModel.objects.filter(value__k={"l":"m"})A workaround is:>>>fromdjango.db.models.expressionsimportRawSQL>>>JSONModel.objects.filter(value__k=RawSQL("PARSE_JSON(%s)",('{"l": "m"}',)))In addition,QuerySet.bulk_update()isn't supported forJSONField.Interval math where the interval is a columnis not supported.Interval math with a null intervalcrashes.TroubleshootingDebug loggingTo troubleshoot issues with connectivity to Snowflake, you can enableSnowflake Connector for Python's loggingusingDjango'sLOGGINGsetting.This is a minimal addition to Django's default"loggers"configuration that
enables the connector'sDEBUGlogging:LOGGING={…"loggers":{…"snowflake.connector":{"level":"DEBUG","handlers":["console"],},},}