Repository navigation
Conversation
Importing the MySQLdb client at module import time forced every component that transitively imports DIRAC.Core.Utilities.MySQL (e.g. via DIRAC.Core.Base.DB or the _quotedList helper) to have the mysql client installed, even when it never contacts a database. This made pilot-side components (JobAgent, PushJobAgent, SingularityComputingElement, and through them the Job Wrapper) fail in minimal pilot environments where the mysql client is not installed. - import MySQLdb lazily in DIRAC/Core/Utilities/MySQL.py, only when an actual database connection is attempted (MySQL.__init__ and ConnectionPool.__newConn) - move the JobDB/TaskQueueDB/JobLoggingDB imports of DIRAC.WorkloadManagementSystem.Utilities.Utils from module level into rescheduleJobs(), the only place where they are instantiated Fixes DIRACGrid#8980
fstagni
force-pushed
the
fix/8980-lazy-mysql-import
branch
from
November 26, 2026 15:04
7789362 to
45821fc
Compare
Contributor
|
Just updated the issue, in recent dirac it also affects opensearch |
This branch has not been deployed
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.
Fixes #8980
Summary
Importing the
MySQLdbclient used to happen at module import time, so every component that transitively importsDIRAC.Core.Utilities.MySQL(e.g. viaDIRAC.Core.Base.DB, or just for the_quotedListhelper) required the mysql client to be installed — even when it never contacts a database. This made pilot-side components fail in minimal pilot environments where the mysql client is missing.Two changes:
DIRAC/Core/Utilities/MySQL.py:MySQLdbis now imported lazily, only when an actual database connection is attempted (MySQL.__init__andConnectionPool.__newConn). This covers every transitive import of DB modules anywhere in the code base.DIRAC/WorkloadManagementSystem/Utilities/Utils.py: theJobDB/TaskQueueDB/JobLoggingDBimports moved from module level intorescheduleJobs(), the only place where they are instantiated. The DB classes are only used by server-side components.Evidence
Importing the utilities no longer loads the mysql client, while instantiating a connection still does:
Pilot-side agent modules import with no mysql module in
sys.modules:A full run of
JobWrapperTemplate(as the pilot executes it) imports no mysql module and behaves unchanged.Tests: all
Core/Utilities(472) andWorkloadManagementSystem(494) tests pass.ruff checkback to the pre-existing baseline.Merge Danger
Door: two-way — trivially revertible, no data or behavior change for components that actually use the databases.
Blast Radius: WMS client/agent imports. The only functional change is when
import MySQLdbhappens: server-side DB instantiation now raisesImportErrorat connection time instead of at module import time, which is what the issue asks for.