Snowflake-Labs / django-snowflake

MIT License
61 stars 16 forks source link

Unable to use the connector with key-pair authentication #101

Closed TanishaBCG closed 2 months ago

TanishaBCG commented 2 months ago

I am having the following settings :

passphrase=os.environ['PRIVATE_KEY_PASSPHRASE'].encode()
private_key_path=Path(os.environ['PRIVATE_KEY'])

DATABASES = {
    'default': {
        'ENGINE': 'Engine',
        'NAME': 'NAME',
        'SCHEMA': 'SCHEMA',
        'WAREHOUSE': 'WAREHOUSE',
        'USER': 'USER',
        'PASSWORD': '#',
        'ACCOUNT': 'ACCOUNT',
        'OPTIONS': {
            'role': 'ROLE',
            'private_key_file': str(private_key_path),
            'private_key_file_pwd': passphrase, 
        },
    }
}

Getting the following error:

Object 'DJANGO_MIGRATIONS' does not exist or not authorized.

Where DJANGO_MIGRATIONS is one of the tables in snowflake, which I am able to access through console, the error is there even when I am not providing the password, otherwise I am facing the following error :

django.core.exceptions.ImproperlyConfigured: settings.DATABASES is missing 'PASSWORD' for 'django_snowflake'.
timgraham commented 2 months ago

What version of this package are you using? You shouldn't get a password required error since django-snowflake 4.2 (with 30856971486e5b64e7c8aa944f341d3e877af38a).

What command are you running when you get the error?

How did you create the django_migrations table if you face this error? You can make sure it's not a database/table permissions issue by using manage.py dbshell as in #45.

TanishaBCG commented 2 months ago

I using

django==5.1
django-snowflake==5.1
python==3.12

both the errors are coming when I am executing

python3 manage.py runserver

Actually the project was working on some previous version of python(3.7), and now we required to use snowflake authenticator, so I upgraded it to the latest versions(all the modules), on older versions it is working fine,

You can make sure it's not a database/table permissions issue by using manage.py dbshell as in https://github.com/Snowflake-Labs/django-snowflake/issues/45.

I will surely look into this.

timgraham commented 2 months ago

Okay, let me know the results of your investigation. Currently, it's unclear whether django-snowflake is at fault.

It also seems as if you may have a typo in your configuration if you're getting the "missing PASSWORD" error while also specifying private_key_file (or else there's a subtle bug I'm missing). See: https://github.com/Snowflake-Labs/django-snowflake/blob/1b867efa8924dc50c63149f099b8d084eaabc13e/django_snowflake/base.py#L93

https://github.com/Snowflake-Labs/django-snowflake/blob/1b867efa8924dc50c63149f099b8d084eaabc13e/django_snowflake/base.py#L115-L116

timgraham commented 2 months ago

If you have any additional information, please leave a comment.