Skip to content

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
masterfrom
fix/config-follow-ups
Open

dimitri-yatsenko wants to merge 2 commits into
masterfrom
fix/config-follow-ups

Conversation

@dimitri-yatsenko

@dimitri-yatsenko dimitri-yatsenko commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

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_LEVEL in any case. DJ_LOG_LEVEL=error python -c "import datajoint" raised a pydantic validation error. The loglevel setting now accepts any case, as logging.py already did. Unknown levels are still rejected.
  • Import-time log records are shown. The settings loaded before the package logger's handler was attached, so the records from that step were lost. The handler is now attached first.
  • The config file loaded at import is logged at DEBUG. Loading configuration from <path> is logged at DEBUG instead of INFO for the config file loaded at import (found by searching, or named by DJ_CONFIG_FILE) and for the one each dj.Instance(...) loads, so neither prints it at the default INFO level. Set DJ_LOG_LEVEL=debug to see which file was loaded. An explicit dj.config.load(path) still logs at INFO, as before. With a datajoint.json you own, import datajoint prints nothing at INFO. A file owned by another user is the exception (next bullets).
  • A skipped file is hard to miss. When a datajoint.json or secrets location is ignored because another user owns it in a location anyone can write, DataJoint now also issues a UserWarning. Before, it only logged a warning, which a logging setup could hide.
  • Another user's file is named when used. A file owned by another user is still used when it sits in a protected directory, such as a shared project folder. That is now logged at INFO: Using <path>, owned by another user (uid <uid>). In a shared project folder whose datajoint.json or secrets directory one user owns, every other user therefore sees this line at the default INFO level, at import and again for each dj.Instance(...). The owner does not, and neither does anyone for a file owned by root.
  • Effective user ID. Ownership is compared with os.geteuid() instead of os.getuid(). This matters under setuid, or after a process changes its effective user.

Fixes #1718.

Behavior change

  • A loglevel set in datajoint.json now takes effect at import. Before, logging.py ran after the settings had loaded and reset the logger to DJ_LOG_LEVEL, or INFO when that was unset. dj.config.loglevel then read, for example, WARNING while the logger still printed INFO records. Now the logger level is the configured one from import on. DJ_LOG_LEVEL still takes precedence over the file.
  • Loading configuration from <path> is logged at DEBUG, not INFO, for the config file loaded at import and by dj.Instance(...). Neither prints it at the default level any more. dj.config.load(path) still logs it at INFO.
  • A skipped config file or secrets location also issues a UserWarning.
  • Using another user's config file or secrets directory from a protected directory logs one INFO line per file, at import and for each dj.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: a mode="before" validator upper-cases loglevel; _is_foreign uses os.geteuid(); _reject_foreign also calls warnings.warn; _read_found_file and _use_found_dir log at info level when they use another user's file; _load_text logs the file path at DEBUG for the file found at import and at INFO for Config.load().
  • src/datajoint/__init__.py: import .logging before the modules that load the settings.

Tests

  • tests/unit/test_settings.py:
    • TestLogLevel: DJ_LOG_LEVEL and assignment in any case; an unknown level still raises.
    • TestImportTimeLogging, each in a new process: import datajoint succeeds with DJ_LOG_LEVEL=error; it prints nothing at the default level with a datajoint.json present; it prints Loading configuration from ... with DJ_LOG_LEVEL=debug; a loglevel of WARNING or debug in datajoint.json is the logger's level after import; DJ_LOG_LEVEL=error overrides a loglevel in the file. In the test process: Config.load() logs the path at INFO.
    • TestDiscoveredFileOwnership: the effective user ID decides ownership; a skipped config file or secrets directory issues a UserWarning, 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.
  • On master, 15 tests fail: 14 new ones, and test_no_posix_ownership_keeps_search, which now removes os.geteuid instead of os.getuid. The new tests that pass on master guard behavior that was already right: DJ_LOG_LEVEL=ERROR, rejecting an unknown level, the quiet import (on master the record was lost rather than logged at DEBUG), Config.load() logging at INFO, no log line for your own file, and the ELOOP tests, which the issue asked for.
  • The unit suite and the full integration suite pass locally on MySQL and PostgreSQL.
  • Running tests/unit and some integration files in one session fails on master too, because some unit tests re-import datajoint. fix(stores): <filepath@> insert checks stores.filepath_default; folder downloads work on older fsspec #1731 fixes that.

Documentation

datajoint/datajoint-docs#317 documents the loglevel change, the UserWarning for a skipped file and the debug-level Loading configuration line, and merges after this PR.

Notes for reviewers

…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.
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

No deployments
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.

Config follow-ups: lowercase DJ_LOG_LEVEL breaks import, import-time log records are lost, skipped config files are easy to miss

1 participant