Skip to content
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

SNOW-1460707: Erroneously Looking for Config.toml File when using DATABASES dictionary in settings.py #1959

Closed
dnich02f opened this issue Jun 3, 2024 · 5 comments · Fixed by #1965
Assignees
Labels
bug status-fixed_awaiting_release The issue has been fixed, its PR merged, and now awaiting the next release cycle of the connector. status-triage_done Initial triage done, will be further handled by the driver team

Comments

@dnich02f
Copy link

dnich02f commented Jun 3, 2024

Python version

Python 3.8

Operating system and processor architecture

Linux-6.6.16-linuxkit-aarch64-with-glibc2.36

Installed packages

Django==4.2.11
django-snowflake==4.2.1
gunicorn==20.0.0

What did you do?

{"status": "error", "message": "[Errno 13] Permission denied: '/root/.config/snowflake/config.toml'"}


I am using django-snowflake, which uses this package.


It is my understanding that since I am referencing all of my environment variables from the DATABASES dictionary (using os.getenv), that the config.toml is not necessary. So I was confused as to why all of a sudden this was file was being searched for. And to be clear, it's not just that Permission denied, it is that the file and directory did not exist at all.


How I fixed the issue:
I added snowfalke-connector-python==3.8.1 to my requirements.txt file before django-snowflake==4.2.*

Why?
I found this in the dist-info/METADATA for snowflake-connector-python 3.10.1:

v3.9.0(April 20,2024)
Added easy logging configuration so that users can easily generate log file by setup log config in $SNOWFLAKE_HOME/config.toml.
Improved s3 acceleration logic when connecting to China endpoint.


Not sure how contributors want to address it, or if it just might be useful for someone searching for solutions to find this.

What did you expect to see?

Nothing. I expected to not have this error at all, as I wasn't experiencing it before.

Can you set logging to DEBUG and collect the logs?

Traceback (most recent call last):
  File "/home/ubuntu/app/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/home/ubuntu/app/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/ubuntu/app/venv/lib/python3.8/site-packages/django/contrib/auth/decorators.py", line 23, in _wrapper_view
    return view_func(request, *args, **kwargs)
  File "xxx", line xxx, in some_function
    snowflake_object = django ORM reference,
  File "/home/ubuntu/app/venv/lib/python3.8/site-packages/django/db/models/query.py", line 1057, in first
    for obj in queryset[:1]:
  File "/home/ubuntu/app/venv/lib/python3.8/site-packages/django/db/models/query.py", line 398, in __iter__
    self._fetch_all()
  File "/home/ubuntu/app/venv/lib/python3.8/site-packages/django/db/models/query.py", line 1881, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/home/ubuntu/app/venv/lib/python3.8/site-packages/django/db/models/query.py", line 91, in __iter__
    results = compiler.execute_sql(
  File "/home/ubuntu/app/venv/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1560, in execute_sql
    cursor = self.connection.cursor()
  File "/home/ubuntu/app/venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/home/ubuntu/app/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 330, in cursor
    return self._cursor()
  File "/home/ubuntu/app/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 306, in _cursor
    self.ensure_connection()
  File "/home/ubuntu/app/venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/home/ubuntu/app/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 289, in ensure_connection
    self.connect()
  File "/home/ubuntu/app/venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/home/ubuntu/app/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 270, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/home/ubuntu/app/venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/home/ubuntu/app/venv/lib/python3.8/site-packages/django_snowflake/base.py", line 137, in get_new_connection
    return Database.connect(**conn_params)
  File "/home/ubuntu/app/venv/lib/python3.8/site-packages/snowflake/connector/__init__.py", line 55, in Connect
    return SnowflakeConnection(**kwargs)
  File "/home/ubuntu/app/venv/lib/python3.8/site-packages/snowflake/connector/connection.py", line 388, in __init__
    easy_logging = EasyLoggingConfigPython()
  File "/home/ubuntu/app/venv/lib/python3.8/site-packages/snowflake/connector/log_configuration.py", line 24, in __init__
    self.parse_config_file()
  File "/home/ubuntu/app/venv/lib/python3.8/site-packages/snowflake/connector/log_configuration.py", line 27, in parse_config_file
    CONFIG_MANAGER.read_config()
  File "/home/ubuntu/app/venv/lib/python3.8/site-packages/snowflake/connector/config_manager.py", line 323, in read_config
    if not filep.exists():
  File "/usr/lib/python3.8/pathlib.py", line 1407, in exists
    self.stat()
  File "/usr/lib/python3.8/pathlib.py", line 1198, in stat
    return self._accessor.stat(self)
PermissionError: [Errno 13] Permission denied: '/root/.config/snowflake/config.toml'
@github-actions github-actions bot changed the title Erroneously Looking for Config.toml File when using DATABASES dictionary in settings.py SNOW-1460707: Erroneously Looking for Config.toml File when using DATABASES dictionary in settings.py Jun 3, 2024
@sfc-gh-dszmolka sfc-gh-dszmolka self-assigned this Jun 4, 2024
@sfc-gh-dszmolka
Copy link
Contributor

sfc-gh-dszmolka commented Jun 4, 2024

hi and thank you for reporting this, also for sharing your workaround. Indeed in django-snowflake with v4.2, we seem to have bumped the snowflake-connector-python minimum dependency from 2.7.4 to 3.6.0 which will install the latest one.

As you noticed, in the more recent PythonConnector versions we now try to read the config from a config.toml but we can agree that perhaps the non-existence of this non-mandatory config file could be handled differently. We'll take a look

edit: looks similar to #1943

@sfc-gh-dszmolka sfc-gh-dszmolka added status-triage_done Initial triage done, will be further handled by the driver team and removed needs triage labels Jun 4, 2024
@sfc-gh-dszmolka sfc-gh-dszmolka removed their assignment Jun 4, 2024
@dnich02f
Copy link
Author

dnich02f commented Jun 4, 2024

@sfc-gh-dszmolka , thank you for looking into it. I don't have a strong opinion on handling the config file, necessarily. Just wanted to bring it to your attention. Thanks again!

edit: I agree that it is similar/the same as the issue you mentioned.

@sfc-gh-dszmolka
Copy link
Contributor

Fix PR already seems to be raised: #1965

@sfc-gh-dszmolka
Copy link
Contributor

reopening to be able to keep track with the release and will close once the release having this fix, is out

@sfc-gh-dszmolka sfc-gh-dszmolka added status-fixed_awaiting_release The issue has been fixed, its PR merged, and now awaiting the next release cycle of the connector. and removed status-pr_pending_merge A PR is made and is under review labels Jun 6, 2024
@sfc-gh-dszmolka
Copy link
Contributor

this should have released with v3.11.0 now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug status-fixed_awaiting_release The issue has been fixed, its PR merged, and now awaiting the next release cycle of the connector. status-triage_done Initial triage done, will be further handled by the driver team
Projects
None yet
4 participants