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 2 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 2 commits into
dimitri-yatsenko wants to merge 2 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.
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.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.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; 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 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.