Skip to content

fix(db,routers): improve DB URLs error handling - #1034

Open
francescobrivio wants to merge 1 commit into
DIRACGrid:mainfrom
francescobrivio:db_url_error_fix
Open

fix(db,routers): improve DB URLs error handling#1034
francescobrivio wants to merge 1 commit into
DIRACGrid:mainfrom
francescobrivio:db_url_error_fix

Conversation

@francescobrivio

Copy link
Copy Markdown
Contributor

PR Description

In this PR I'm improving the error reporting when DB_URL env variables are missing as suggested in the "Proposed Changes" section of #46.

PR Validation

Manually tweaking BaseSQLDB.available_urls() and BaseOSDB.available_urls() I was able to generate the desired warning messages:

  • SQL:
    2026-09-05 17:02:04,332 - WARNING - TaskQueueDB found but no URL connection set: please set DIRACX_DB_URL_TASKQUEUEDB env variable to enable it.
    
  • OpenSearch:
    2026-09-07 18:48:02,885 - WARNING - JobParametersDB found but no URL connection set: please set DIRACX_OS_DB_JOBPARAMETERSDB env variable to enable it.
    

Additionally, manually tweaking diracx-db/src/diracx/db/__main__.py.generate_local_urls() I was able to reproduce the desired error messages:

  • For "No SQL database could be initialized":
    Exception: No SQL database could be initialized, aborting. Please set the following env variables to enable it:
     DIRACX_DB_URL_JOBDB
     DIRACX_DB_URL_LOLLYGAGDB
     DIRACX_DB_URL_MYPILOTDB
     DIRACX_DB_URL_AUTHDB
     DIRACX_DB_URL_JOBDB
     DIRACX_DB_URL_JOBLOGGINGDB
     DIRACX_DB_URL_PILOTAGENTSDB
     DIRACX_DB_URL_RESOURCESTATUSDB
     DIRACX_DB_URL_SANDBOXMETADATADB
     DIRACX_DB_URL_TASKQUEUEDB
     DIRACX_DB_URL_TASKDB
    
  • For "Cannot enable system…":
    • SQL:
      NotImplementedError: Cannot enable system_name='jobs' please set the following env variables to enable it:
       DIRACX_DB_URL_TASKQUEUEDB
       DIRACX_DB_URL_JOBDB
      
    • OpenSearch:
      NotImplementedError: Cannot enable system_name='jobs' please set the following env variables to enable it:
       DIRACX_OS_DB_JOBPARAMETERSDB
      

DoD

  • Starting a service whose DB env variable is unset produces an error message that contains the literal environment variable name to set (e.g. DIRACX_DB_URL_JOBDB).
  • Starting with no DB URLs configured at all produces an error explaining that connection URLs are provided via DIRACX_DB_URL_ / DIRACX_OS_DB_ variables.
  • DBs that are discovered but unconfigured are logged (warning level) at startup instead of being silently skipped, for both SQL and OpenSearch databases.
  • Behavior is covered by tests (missing single DB, no DBs at all, OpenSearch variant) if possible.
  • Malformed-URL error handling is unchanged.

Closes #46

@francescobrivio francescobrivio self-assigned this Sep 7, 2026
@francescobrivio

Copy link
Copy Markdown
Contributor Author

I still need to work on the test coverage, but while I understand exactly how the tests work, I'd like to hear your feedback on the implemented fix @chaen @aldbr @fstagni. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Better error reporting when DB_URL env variables are missing

1 participant