Skip to content

fix(declare): reject constant defaults on primary-key attributes - #1759

Open
godara-alt wants to merge 3 commits into
datajoint:masterfrom
godara-alt:fix/1712-reject-constant-pk-defaults
Open

godara-alt wants to merge 3 commits into
datajoint:masterfrom
godara-alt:fix/1712-reject-constant-pk-defaults

Conversation

@godara-alt

Copy link
Copy Markdown
Contributor

Summary

Fixes #1712.

Reject constant defaults on user-defined primary-key attributes at declaration time, while preserving generated CURRENT_TIMESTAMP defaults and existing behavior for secondary attributes.

Root Cause

The declaration compiler previously rejected nullable primary-key attributes but allowed constant defaults.

This permitted insertions without an explicitly supplied primary-key value, causing repeated insertions to reuse the same constant key.

Changes

  • Reject constant numeric and string defaults on primary-key attributes with a descriptive DataJointError.

  • Continue allowing generated CURRENT_TIMESTAMP defaults.

  • Preserve the framework-generated _singleton sentinel, restricting its exception to the internal declaration path.

  • Remove the redundant omega=0 default from the university test schema, where the CSV already supplies the key explicitly.

  • Add regression tests covering MySQL and PostgreSQL adapters, constant defaults, generated defaults, secondary attributes and singleton behavior.

Testing and Verification

Final commit: b43425beb2c6ef0c94627708c1602bb96eec8fb5

Verified using GitHub Actions on the fork:

Test | Result -- | -- Lint and formatting | Passed Linux unit tests | Passed Windows unit tests (Python 3.10, 3.14, 3.15) | Passed MySQL integration tests (6 configurations) | Passed Minimum dependency versions (Python 3.10) | Passed

Final result: All 12 checks passed, with zero failures and zero pending checks.

Scope

The changes are limited to:

  • src/datajoint/declare.py

  • tests/schema_university.py

  • tests/unit/test_primary_key_defaults.py

No new dependencies were introduced and no tests were disabled.

The branch is up to date with upstream master.

Ready for review.

…ajoint#1712)

Permit generated CURRENT_TIMESTAMP defaults, preserve secondary defaults,
and test declarations across MySQL and PostgreSQL adapters.
… test fixture

Allow the platform-created singleton sentinel its fixed default without exposing that exception to user declarations. Remove a redundant constant key default from the university fixture, whose CSV supplies an explicit key. Add regression tests.

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.

Reject constant defaults on primary-key attributes

1 participant