Move report queries onto Django's DB connection#4131
Open
adobloug wants to merge 1 commit into
Open
Conversation
The report subsystem read from the database through the legacy nav.db.getConnection() cache (nav.ObjectCache), which is not thread-safe and misbehaves under mod_wsgi's multithreaded workers (same root cause as Uninett#4104): cached connections can leak or cross threads, causing intermittent errors and HTTP 500s. Migrate DatabaseResult, IPtree.get_subnets and MetaIP._createMetaMap to django.db.connection, whose connections are thread-local. metaIP dropped its legacy 'manage' database alias, which already resolved to the same 'nav' database (no db_manage in db.conf), so this is behaviourally a no-op. DB-API errors now surface as django.db.utils.* exceptions rather than psycopg2.*, so dbresult.py catches ProgrammingError and DataError from django.db.utils; otherwise a malformed report SQL definition would raise uncaught and produce an HTTP 500. Add integration tests that exercise the real connection path, including the malformed-SQL and invalid-type error handling. Fixes Uninett#4130.
|
10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Scope and purpose
Fixes #4130.
The report subsystem read from the database through the legacy
nav.db.getConnection()cache (nav.ObjectCache), which is not thread-safe andmisbehaves under mod_wsgi's multithreaded workers — the same root cause as #4104.
This moves
DatabaseResult,IPtree.get_subnetsandMetaIP._createMetaMaponto Django's
django.db.connection, whose connections are thread-local, takingreports off the fragile legacy cache.
metaIPdropped its legacy'manage'database alias, which already resolved tothe same
navdatabase (nodb_managein db.conf), so that is behaviourally ano-op.
DB-API errors now surface as
django.db.utils.*exceptions rather thanpsycopg2.*.dbresult.pyis updated to catchProgrammingError/DataErrorfrom
django.db.utils; without this a malformed report SQL definition wouldraise uncaught and produce an HTTP 500 — the regression flagged in the review of
#4111.
Split out from #4111 (issue #4104) as a separable change, per review feedback.
How to observe
The new integration tests exercise the real
django.db.connectionpath,including the error handling:
test_when_report_sql_is_malformed_then_error_is_set_without_raisingandtest_when_report_input_type_is_invalid_then_data_error_is_setfail against theold
psycopg2handlers (uncaughtdjango.db.utils.*→ HTTP 500) and pass withthe Django-wrapped handlers.
Contributor Checklist
5.19.x, a bugfix affecting the latest stable version)