Skip to content

Test: Add tests to ensure every DB table has a default entry in schem… - #8341

Merged
CarolineDenis merged 10 commits into
mainfrom
issue-8078
Jul 29, 2026
Merged

Test: Add tests to ensure every DB table has a default entry in schem…#8341
CarolineDenis merged 10 commits into
mainfrom
issue-8078

Conversation

@CarolineDenis

@CarolineDenis CarolineDenis commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

…a_localization_en.json

Fixes #8078

Checklist

  • Self-review the PR after opening it to make sure the changes look good and
    self-explanatory (or properly documented)
  • Add relevant issue to release milestone
  • Add pr to documentation list
  • Add automated tests
  • Add a reverse migration if a migration is present in the PR
  • Add migration function to
    def fix_schema_config(stdout: WriteToStdOut | None = None):

Testing instructions

Summary by CodeRabbit

  • Tests
    • Added automated checks ensuring every model-backed database table is represented in the schema localization file.
    • Added validation to report both missing and extra localization keys, including counts and the specific affected tables.
  • New Features
    • Added a new component section to the schema localization configuration, including localized field metadata for component-related entries.

@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown

Warning

One or more dependencies are approaching or past End-of-Life.
Please plan upgrades accordingly.

STATUS=WARNING
NODE_VERSION=20
NODE_CYCLE=20
EOL_DATE=2026-04-30
DAYS_REMAINING=-90

--- Node.js ---
Version: 20
EOL: 2026-04-30
Status: WARNING

STATUS=OK
PYTHON_VERSION=3.12
PYTHON_CYCLE=3.12
EOL_DATE=2028-10-31
DAYS_REMAINING=825

--- Python ---
Version: 3.12
EOL: 2028-10-31
Status: OK

STATUS=WARNING
DJANGO_VERSION=4.2
DJANGO_CYCLE=4.2
EOL_DATE=2026-04-07
DAYS_REMAINING=-113

--- Django ---
Version: 4.2
EOL: 2026-04-07
Status: WARNING


@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f81993bf-b1f3-46bf-b02e-aae7872a38f2

📥 Commits

Reviewing files that changed from the base of the PR and between 657dcd7 and 3a7f78c.

📒 Files selected for processing (2)
  • config/common/schema_localization_en.json
  • specifyweb/specify/tests/test_schema_localization_contract.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • specifyweb/specify/tests/test_schema_localization_contract.py

📝 Walkthrough

Walkthrough

Adds a Django test that parses model table declarations, compares them with schema_localization_en.json, permits approved JSON-only tables, and adds localization metadata for the component table.

Changes

Schema localization coverage

Layer / File(s) Summary
Component localization entry
config/common/schema_localization_en.json
Adds the component schema localization block with field types, labels, descriptions, required and hidden flags, and related metadata.
Table discovery and test setup
specifyweb/specify/tests/test_schema_localization_contract.py
Defines allowed JSON-only tables, loads the localization JSON, and extracts lowercased Meta.db_table values from model classes using the Python AST.
Localization coverage validation
specifyweb/specify/tests/test_schema_localization_contract.py
Compares model tables with localization keys, applies the allowlist for JSON-only tables, and fails with actionable missing or unexpected entries.

Suggested reviewers: grantfitzsimmons

🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Testing Instructions ⚠️ Warning The PR’s Testing instructions section is only template comments; it gives no runnable steps for the new contract test or JSON change. Add concrete verification steps, e.g. run the new schema localization contract test and note any broader checks covering config/common/schema_localization_en.json.
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding tests for default schema localization entries.
Linked Issues check ✅ Passed The new contract test compares model table slugs to schema_localization_en.json, reports missing and extra keys, and supports an allowlist.
Out of Scope Changes check ✅ Passed The added test and component localization entry both directly support the stated schema localization objectives.
Automatic Tests ✅ Passed A new automated test module was added under specifyweb/specify/tests, with a TestCase that checks schema_localization_en.json against model tables.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-8078

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@specifyweb/specify/tests/test_schema_localization_contract.py`:
- Around line 37-38: Update the AST extraction logic in the schema localization
contract test to retain each associated model name alongside the lowercased
table slug instead of storing only stmt.value.value. Propagate that model name
into the missing-entry failure reported by the test so failures identify the
model and table involved, while preserving the existing table-name matching
behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1c06851d-778a-4988-93e0-6cf5860402e3

📥 Commits

Reviewing files that changed from the base of the PR and between 8f38321 and f35ca7c.

📒 Files selected for processing (1)
  • specifyweb/specify/tests/test_schema_localization_contract.py

Comment thread specifyweb/specify/tests/test_schema_localization_contract.py Outdated
@github-project-automation github-project-automation Bot moved this from 📋Back Log to Dev Attention Needed in General Tester Board Jul 22, 2026
@grantfitzsimmons
grantfitzsimmons self-requested a review July 23, 2026 12:56

@grantfitzsimmons grantfitzsimmons left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty cool idea! Nice!

  • When there are no unexpected extras, printing "Unexpected schema localization-only tables:" with nothing after it is not needed.
  • The allowlist is also part of the body, but should we maintain this list elsewhere? Are these tables excluded from any other part of the app (e.g. schema config) or should be?
  • We could add feedback for future developers here like "Add entries to the schema_localization_en.json file or update the allowlist"
  • A count summary of the number of tables at the top would be nice, but totally optional

@CarolineDenis CarolineDenis modified the milestones: 7.12.2, 7.12.1 Jul 27, 2026

@grantfitzsimmons grantfitzsimmons left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR now adds defaults for component (which I should have done a long time ago). It matches MIGRATION_0040_UPDATE_FIELDS in sp7_schemaconfig.py:

MIGRATION_0040_UPDATE_FIELDS = {
'Component': [
('type', 'Type', 'Determines the valid options for component names.'),
('name', 'Name', 'The name from a taxon tree corresponding to the chosen type.'),
('verbatimName', 'Verbatim Name', 'The original name printed or associated with the component.'),
('role', 'Role', 'Define the role or purpose of the component in the overall collection.'),
('proportion', 'Proportion', 'Specify the proportion of the component relative to the whole.'),
('uniqueIdentifier', 'Unique Identifier', 'Uniquely identifies each component record'),
('catalogNumber', 'Catalog Number', 'User-assigned identifier for the component'),
],
}

I added the remaining many-to-many join tables (autonumsch_coll, autonumsch_div, autonumsch_dsp, project_colobj, sp_schema_mapping, specifyuser_spprincipal, spprincipal_sppermission) to the allowlist since we do not want these to have schema config records.

@CarolineDenis
CarolineDenis merged commit 4b3ced8 into main Jul 29, 2026
20 checks passed
@CarolineDenis
CarolineDenis deleted the issue-8078 branch July 29, 2026 07:02
@github-project-automation github-project-automation Bot moved this from Dev Attention Needed to ✅Done in General Tester Board Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅Done

Development

Successfully merging this pull request may close these issues.

Ensure every DB table has a default entry in schema_localization_en.json

2 participants