Repository navigation
fix(settings): DJ_LOG_LEVEL accepts any case; config files loaded or skipped at import are reported - #1736
Open
dimitri-yatsenko wants to merge 4 commits into
Open
fix(settings): DJ_LOG_LEVEL accepts any case; config files loaded or skipped at import are reported#1736dimitri-yatsenko wants to merge 4 commits into
dimitri-yatsenko wants to merge 4 commits into
Conversation
…records - The loglevel setting accepts any case, so DJ_LOG_LEVEL=error no longer makes `import datajoint` fail. - The package logger's handler is attached before the settings load, so the records emitted at import time (which config file was loaded or skipped) are shown. - A config file or secrets directory skipped because another user owns it in a location anyone can write is also reported with warnings.warn. - Using a file found by searching that another user owns is logged at info level, with its path and owner. - File ownership is compared with the effective user ID. - Test: a symbolic-link loop at a secret file name is skipped with a warning. Fixes #1718.
dimitri-yatsenko
requested review from
MilagrosMarin,
lum-agilyti and
ttngu207
November 21, 2026 01:38
import datajoint printed 'Loading configuration from <path>' at the default INFO level once the handler was attached before the settings load. The file found at import is now logged at DEBUG; an explicit dj.config.load() still logs at INFO. Tests cover the quiet import, the loglevel from datajoint.json applying at import, and DJ_LOG_LEVEL overriding it. The test module imports the log levels with 'from logging import ...' so that its import block does not collide with the one in the environment-variable precedence change.
MilagrosMarin
left a comment
Contributor
There was a problem hiding this comment.
Thanks @dimitri-yatsenko, this closes the gaps from #1718 cleanly.
- Ran the settings tests (135 pass) and the full unit (1099) and integration (974 pass, 17 skipped) suites with master merged in. With master's
src/restored, 15 of the settings tests fail, as the description says. import datajointwith adatajoint.jsonpresent writes nothing to stdout or stderr at the default level.DJ_LOG_LEVEL=debugshows theLoading configuration from ...line.DJ_LOG_LEVEL=errorandERRORboth set the logger to 40.- One regression from the import reorder: because
logging.pynow runs before the settings are validated,DJ_LOG_LEVEL=bogusfails withValueError: Unknown level: 'BOGUS'fromlogging.setLevel, instead of the previous pydantic error that namedDJ_LOG_LEVELand listed the allowed levels.DJ_LOG_LEVEL=" info"hits the same path. Couldlogging.pycheck the value against the allowed levels (or fall back to INFO and let the settings validation raise), with a test for an invalid value at import? - Minor, for the docs PR: log records go to stdout by default while the new
UserWarninggoes to stderr, so a skipped file shows up once on each stream.
Once the invalid-level message names the variable again, the import-time logging story here is in good shape.
logging.py now runs before the settings load, and passed an unknown level straight to logger.setLevel, so DJ_LOG_LEVEL=bogus failed with "ValueError: Unknown level: 'BOGUS'". It now falls back to INFO on a level logging does not recognize, and the settings validation raises its error, which names DJ_LOG_LEVEL and lists the allowed levels. The allowed levels stay defined in one place, the settings.
MilagrosMarin
approved these changes
Nov 30, 2026
MilagrosMarin
left a comment
Contributor
There was a problem hiding this comment.
Thanks @dimitri-yatsenko, the logging.py fallback does it.
DJ_LOG_LEVEL=bogusand" info"now fail with the settings error that namesDJ_LOG_LEVELand lists the allowed levels. With the previouslogging.pyrestored, the new test fails for both, so it guards the fix.test_settings.py(138) and the unit suite (1102) pass on the head commit.
Two minor observations on the "Using , owned by another user" line, neither blocking:
- In a shared project folder, a non-owner sees one INFO line for the config file, one for
.secrets, and one for each secret file in it. Withdatabase.user,database.passwordand onestores.*file, that is five lines on every import, and again perdj.Instance(...). Since the folder line already names the location, could the files read from a secrets directory that was just accepted log at DEBUG? - The line for the config file is logged before that file's
loglevelis applied, so a shareddatajoint.jsonwith"loglevel": "WARNING"still prints it at import. Fine to leave as is, but worth a sentence in datajoint/datajoint-docs#317 next to theloglevelchange.
With the invalid-level message restored, this is ready from my side.
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.
Summary
Follow-ups to the 2.3.6 changes for config and secret files found by searching (GHSA-88hh-c8vj-9xx9), and two problems with the log level.
DJ_LOG_LEVELin any case.DJ_LOG_LEVEL=error python -c "import datajoint"raised a pydantic validation error. Theloglevelsetting now accepts any case, aslogging.pyalready did. Unknown levels are still rejected.logging.pynow runs before the settings are checked, it falls back toINFOon a level it does not recognize, so an invalidDJ_LOG_LEVEL(such asbogusorinfo) still fails with the settings error that namesDJ_LOG_LEVELand lists the allowed levels, not withValueError: Unknown level.DEBUG.Loading configuration from <path>is logged atDEBUGinstead ofINFOfor the config file loaded at import (found by searching, or named byDJ_CONFIG_FILE) and for the one eachdj.Instance(...)loads, so neither prints it at the defaultINFOlevel. SetDJ_LOG_LEVEL=debugto see which file was loaded. An explicitdj.config.load(path)still logs atINFO, as before. With adatajoint.jsonyou own,import datajointprints nothing atINFO. A file owned by another user is the exception (next bullets).datajoint.jsonor secrets location is ignored because another user owns it in a location anyone can write, DataJoint now also issues aUserWarning. Before, it only logged a warning, which a logging setup could hide.INFO:Using <path>, owned by another user (uid <uid>).In a shared project folder whosedatajoint.jsonor secrets directory one user owns, every other user therefore sees this line at the defaultINFOlevel, at import and again for eachdj.Instance(...). The owner does not, and neither does anyone for a file owned by root.os.geteuid()instead ofos.getuid(). This matters undersetuid, or after a process changes its effective user.Fixes #1718.
Behavior change
loglevelset indatajoint.jsonnow takes effect at import. Before,logging.pyran after the settings had loaded and reset the logger toDJ_LOG_LEVEL, orINFOwhen that was unset.dj.config.loglevelthen read, for example,WARNINGwhile the logger still printedINFOrecords. Now the logger level is the configured one from import on.DJ_LOG_LEVELstill takes precedence over the file.Loading configuration from <path>is logged atDEBUG, notINFO, for the config file loaded at import and bydj.Instance(...). Neither prints it at the default level any more.dj.config.load(path)still logs it atINFO.UserWarning.INFOline per file, at import and for eachdj.Instance(...). In a shared project folder, each user other than the file's owner sees it at the default level.Changes
src/datajoint/settings.py: amode="before"validator upper-casesloglevel;_is_foreignusesos.geteuid();_reject_foreignalso callswarnings.warn;_read_found_fileand_use_found_dirlog at info level when they use another user's file;_load_textlogs the file path atDEBUGfor the file found at import and atINFOforConfig.load().src/datajoint/__init__.py: import.loggingbefore the modules that load the settings.src/datajoint/logging.py: fall back toINFOwhenDJ_LOG_LEVELis not a levelloggingrecognizes, leaving the check of allowed levels to the settings.Tests
tests/unit/test_settings.py:TestLogLevel:DJ_LOG_LEVELand assignment in any case; an unknown level still raises.TestImportTimeLogging, each in a new process:import datajointsucceeds withDJ_LOG_LEVEL=error; withDJ_LOG_LEVELset tobogus,info, orjobsit fails with an error that namesDJ_LOG_LEVELand lists the allowed levels; it prints nothing at the default level with adatajoint.jsonpresent; it printsLoading configuration from ...withDJ_LOG_LEVEL=debug; aloglevelofWARNINGordebugindatajoint.jsonis the logger's level after import;DJ_LOG_LEVEL=erroroverrides aloglevelin the file. In the test process:Config.load()logs the path atINFO.TestDiscoveredFileOwnership: the effective user ID decides ownership; a skipped config file or secrets directory issues aUserWarning, even with the logger disabled; using another user's config file or secrets directory is logged at info level, and using your own is not; a symbolic-link loop (ELOOP) at a secret file name is skipped with a warning.master, 15 tests fail: 14 new ones, andtest_no_posix_ownership_keeps_search, which now removesos.geteuidinstead ofos.getuid. The new tests that pass onmasterguard behavior that was already right:DJ_LOG_LEVEL=ERROR, rejecting an unknown level, the invalid-level error at import (it regressed on this branch before thelogging.pyfallback), the quiet import (onmasterthe record was lost rather than logged atDEBUG),Config.load()logging atINFO, no log line for your own file, and theELOOPtests, which the issue asked for.tests/unitand some integration files in one session fails onmastertoo, because some unit tests re-importdatajoint. fix(stores): <filepath@> insert checks stores.filepath_default; folder downloads work on older fsspec #1731 fixes that.Documentation
datajoint/datajoint-docs#317 documents the
loglevelchange, theUserWarningfor a skipped file and the debug-levelLoading configurationline, and merges after this PR.Notes for reviewers
tests/unit/test_settings.py. The two used to conflict in the module's import lines; this PR now imports the log levels withfrom logging import ..., so the branches merge cleanly in either order.tests/unit/test_settings.pypasses on the merge of the two branches.