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

Warn when database config isn't readable #2341

Closed
lunkwill42 opened this issue Jan 4, 2022 · 0 comments · Fixed by #2346
Closed

Warn when database config isn't readable #2341

lunkwill42 opened this issue Jan 4, 2022 · 0 comments · Fixed by #2346
Labels
bug good first issue Needs no networking experience and is assumedly small
Milestone

Comments

@lunkwill42
Copy link
Member

This code handles configuration of the DATABASES Django setting from NAV's standard db.conf file:

# Database / ORM configuration
try:
_appname = os.path.basename(sys.argv[0])
_host, _port, _name, _user, _password = get_connection_parameters('django')
DATABASES = {
'default': {
'NAME': _name,
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'HOST': _host,
'PORT': _port,
'USER': _user,
'PASSWORD': _password,
'CONN_MAX_AGE': 300, # 5 minutes
'OPTIONS': {
'application_name': _appname or 'NAV',
},
}
}
except (IOError, OSError):
pass

It quietly ignores issues with reading the db.conf config, to ensure NAV code can still be imported during development or unit testing, when no database is actually running.

However, this masks issues with getting parts of NAV to run in production. E.g. if the NAV web app doesn't run with the necessary privilege level to read db.conf, the app will crash with only a generic Django ImproperlyConfigured error for the DATABASES setting - leaving the user to figure out for themselves what the actual underlying problem is.

Solution

The exception handler needs to be there, due to the reasons described above, but it should at least output a warning containing a description of the caught exception, so the problem will be easier to track down for an end user.

@lunkwill42 lunkwill42 added bug good first issue Needs no networking experience and is assumedly small labels Jan 4, 2022
@lunkwill42 lunkwill42 added this to the 5.3.0 milestone Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug good first issue Needs no networking experience and is assumedly small
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant