Skip to content

OpenConceptLab/ocl_issues#2911 | Load base_entities.yaml only on a new database - #939

Merged
snyaggarwal merged 4 commits into
masterfrom
fix/ocl_issues-2911-keep-ocl-org
Oct 14, 2026
Merged

snyaggarwal merged 4 commits into
masterfrom
fix/ocl_issues-2911-keep-ocl-org

Conversation

@paynejd

@paynejd paynejd commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

closes OpenConceptLab/ocl_issues#2911

Problem

pre_startup.sh ran python manage.py loaddata core/fixtures/* on every container start. base_entities.yaml pins the OCL org at pk 1 with only name, company, mnemonic and website, and loaddata overwrites an existing row in full. So every deploy put the OCL org back to its 2020 seed values: name "OCL", no text, description, logo or overview. The About text and logo set on 2026-10-08 for OpenConceptLab/ocl_issues#2886 were gone after the next deploy.

Change

  • The OCL org moves from base_entities.yaml into its own fixture, ocl_org.yaml.
  • New manage.py load_fixtures: loads every file in core/fixtures as before, but skips ocl_org.yaml once the OCL org exists. A new database is still seeded with the org.
  • pre_startup.sh calls it instead of loaddata core/fixtures/*.
  • The test base classes load ocl_org.yaml next to base_entities.yaml.
  • The comment in auth_groups.yaml that named the old command now names the new one.

Everything else, including ocladmin in base_entities.yaml, still reloads on every start, so ocladmin's flags are restored as they always were.

Tests

core/common/tests_load_fixtures.py:

  • an existing OCL org keeps its name, text, description and overview;
  • the other fixtures still overwrite (a changed capability description is restored);
  • a demoted or deactivated ocladmin is restored by startup (load_fixtures then setup_superuser);
  • with no OCL org and no ocladmin, both are seeded.

With the old behaviour (loading the org fixture unconditionally), the first test fails. All four pass with the change; pylint scores 10.00 on the changed Python files.

After merge and deploy

The OCL org's content (name, logo, About text, description and banner) must be set again (OpenConceptLab/ocl_issues#2886). After this deploys, it stays.

🤖 Generated with Claude Code

https://claude.ai/code/session_018wMfkJ379WBjtcv8ZiWpT4

paynejd and others added 2 commits October 13, 2026 16:03
…on a new database, so deploys stop resetting the OCL org

pre_startup.sh ran `loaddata core/fixtures/*` on every container start. loaddata
overwrites an existing row in full, so each deploy put the OCL org (pk 1) back to
its 2020 seed values and wiped its text, description, logo and overview.

The new `load_fixtures` command loads every file in core/fixtures as before, but
skips base_entities.yaml once the OCL org exists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018wMfkJ379WBjtcv8ZiWpT4
…superuser and staff flags itself

The base_entities.yaml reload used to reset them on every start. Without it, a
demoted ocladmin made setup_superuser's lookup (is_superuser=True) fail and stop
the container from starting (Codex review pass 1, F1.1).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018wMfkJ379WBjtcv8ZiWpT4
@paynejd

paynejd commented Oct 13, 2026

Copy link
Copy Markdown
Member Author

Codex review, pass 1 (codex-cli 0.162.1, commit 7e3b528)

Verdict: 1 finding (P2), fixed in ea7de7a.

  • F1.1 (P2): load_fixtures.py:20. With base_entities.yaml skipped on existing databases, a demoted ocladmin (is_superuser=False) makes setup_superuser's lookup fail and stops the container from starting. The reload used to restore the flag.
    Response: fixed. setup_superuser now finds ocladmin by username and sets is_superuser and is_staff itself; test_startup_restores_a_demoted_ocladmin covers it.
findings.json
{
  "reviewer": "codex-cli 0.162.1",
  "perspective": "defects",
  "mode": "full",
  "commit": "7e3b528bdae0d49c4958261c8da565daec0d5c52",
  "verdict": "findings",
  "prior": [],
  "findings": [
    {
      "id": "F1.1",
      "severity": "P2",
      "tag": null,
      "file": "core/common/management/commands/load_fixtures.py",
      "line": 20,
      "claim": "Skipping the entire fixture can break subsequent container starts when ocladmin has been demoted.",
      "scenario": "In standalone mode, another staff user can demote ocladmin through PUT /users/ocladmin/staff/, setting is_superuser=False. With organization ID 1 present, this command now skips the user seed. The following setup_superuser command requires username='ocladmin', is_superuser=True, so it raises DoesNotExist and aborts startup. Previously, reloading base_entities.yaml restored that flag before setup_superuser ran.",
      "action": "Initialize the required ocladmin state independently of organization seeding, or make setup_superuser restore its required flags without filtering them in the lookup. Add a regression test for startup after demotion.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

…ase; keep reloading ocladmin as before

Moves the OCL org from base_entities.yaml to ocl_org.yaml, which load_fixtures
skips once the org exists. base_entities.yaml (ocladmin) reloads on every start
as before, so a demoted or deactivated ocladmin is restored as it always was, and
setup_superuser goes back to master (Codex review pass 2, F2.1, and pass 1, F1.1).
The fresh-database test now deletes both the org and ocladmin (F2.2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018wMfkJ379WBjtcv8ZiWpT4
@paynejd

paynejd commented Oct 13, 2026

Copy link
Copy Markdown
Member Author

Codex review, pass 2 (codex-cli 0.162.1, commit ea7de7a)

Verdict: F1.1 resolved; 2 new findings (P2), both addressed in 72473ee by a different approach.

  • F2.1 (P2): setup_superuser.py:16. A deactivated ocladmin (is_active/verified false) was restored by the old reload but not by the new setup_superuser code.
    Response: fixed by narrowing what's skipped instead. The OCL org moved from base_entities.yaml into its own ocl_org.yaml, which load_fixtures skips once the org exists. base_entities.yaml (ocladmin) reloads on every start as before, so ocladmin is restored exactly as it always was, and setup_superuser is back to master. test_startup_restores_a_demoted_or_deactivated_ocladmin covers both flags.
  • F2.2 (P2): tests_load_fixtures.py:44. The fresh-database test kept ocladmin from the test setup.
    Response: fixed. The test now deletes both the OCL org and ocladmin, then checks that load_fixtures creates both.
findings.json
{
  "reviewer": "codex-cli 0.162.1",
  "perspective": "defects",
  "mode": "verify",
  "commit": "ea7de7ac2baba256daf5f7b60989c5da2005ac88",
  "verdict": "findings",
  "prior": [
    {
      "id": "F1.1",
      "status": "resolved"
    }
  ],
  "findings": [
    {
      "id": "F2.1",
      "severity": "P2",
      "tag": null,
      "file": "core/common/management/commands/setup_superuser.py",
      "line": 16,
      "claim": "Startup no longer restores a deactivated ocladmin's ability to authenticate.",
      "scenario": "Another administrator deactivates ocladmin through the supported DELETE endpoint, setting is_active=False and verified=False. Previously, reloading base_entities restored both defaults. Startup now restores privileges and credentials but leaves those flags false: the configured API token is rejected and password login enters the reactivation flow.",
      "action": "Restore ocladmin's active and verified state alongside its privilege flags, and add a regression test covering startup after deactivate().",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F2.2",
      "severity": "P2",
      "tag": null,
      "file": "core/common/tests_load_fixtures.py",
      "line": 44,
      "claim": "The fresh-database test does not cover creation of the required ocladmin user.",
      "scenario": "OCLTestCase.setUpClass already loads base_entities, and this test deletes only the organization. The preexisting ocladmin remains, so the test would pass even if fresh startup stopped creating that user, leaving the ticket's fresh-database acceptance criterion incompletely tested.",
      "action": "Run the fresh-database case without preloaded base entities, assert both entities are initially absent, then verify that load_fixtures creates the OCL organization and ocladmin.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

@paynejd

paynejd commented Oct 13, 2026

Copy link
Copy Markdown
Member Author

Codex review, pass 3 (codex-cli 0.162.1, commit 72473ee)

Verdict: clean. F1.1, F2.1 and F2.2 are resolved, and no new findings.

findings.json
{
  "reviewer": "codex-cli 0.162.1",
  "perspective": "defects",
  "mode": "verify",
  "commit": "72473eeb88438bac122878f9996e827853841dd8",
  "verdict": "clean",
  "prior": [
    {"id": "F1.1", "status": "resolved"},
    {"id": "F2.1", "status": "resolved"},
    {"id": "F2.2", "status": "resolved"}
  ],
  "findings": []
}

…org test, drop a repeated comment

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018wMfkJ379WBjtcv8ZiWpT4
@paynejd

paynejd commented Oct 13, 2026

Copy link
Copy Markdown
Member Author

Simplification review (fresh Claude subagent, commit 72473ee)

Verdict: 4 cuts proposed; 2 applied in 229a7a5. A Codex check of that commit came back clean.

  • S1 (shrink), core/common/tests.py:279: have the test base classes call load_fixtures instead of four loaddata calls. Declined: every test's setup would then depend on the command under test, so a bug in it would break the whole suite instead of one test.
  • S2 (shrink), tests_load_fixtures.py:10: one dict assertion instead of four. Applied.
  • S3 (dup-test), tests_load_fixtures.py:33: merge the ocladmin and capabilities tests. Declined: they cover separate acceptance criteria and fail separately.
  • S4 (delete), load_fixtures.py:18: the inline comment repeats the ocl_org.yaml header and the help string. Applied.

Check of cuts (codex-cli 0.162.1, commit 229a7a5): clean.

simplify.json
{
  "reviewer": "claude subagent",
  "perspective": "simplify",
  "mode": "full",
  "commit": "72473eeb88438bac122878f9996e827853841dd8",
  "verdict": "findings",
  "prior": [],
  "findings": [
    {
      "id": "S1",
      "severity": null,
      "tag": "shrink",
      "file": "core/common/tests.py",
      "line": 279,
      "claim": "The three test base classes list the fixture files in four loaddata calls; load_fixtures already loads that set.",
      "action": "Replace the four loaddata lines in each setUpClass with call_command('load_fixtures').",
      "lines_delta": -9,
      "confidence": "medium",
      "scenario": null
    },
    {
      "id": "S2",
      "severity": null,
      "tag": "shrink",
      "file": "core/common/tests_load_fixtures.py",
      "line": 10,
      "claim": "test_keeps_an_existing_ocl_org sets four attributes and makes four assertEquals; the same check fits in a dict.",
      "action": "update(**edits) then assertEqual(values(*edits).get(), edits)",
      "lines_delta": -8,
      "confidence": "medium",
      "scenario": null
    },
    {
      "id": "S3",
      "severity": null,
      "tag": "dup-test",
      "file": "core/common/tests_load_fixtures.py",
      "line": 33,
      "claim": "The ocladmin test and the capabilities test both assert that load_fixtures reloads every fixture except ocl_org.yaml.",
      "action": "Merge into one test_reloads_every_fixture_but_the_ocl_org.",
      "lines_delta": -4,
      "confidence": "low",
      "scenario": null
    },
    {
      "id": "S4",
      "severity": null,
      "tag": "delete",
      "file": "core/common/management/commands/load_fixtures.py",
      "line": 18,
      "claim": "The reason ocl_org.yaml is seed-only appears three times (help string, inline comment, fixture header).",
      "action": "Nothing replaces it; keep the help string and the ocl_org.yaml header.",
      "lines_delta": -2,
      "confidence": "low",
      "scenario": null
    }
  ]
}
cuts.json
{
  "reviewer": "codex-cli 0.162.1",
  "perspective": "defects",
  "mode": "cuts",
  "commit": "229a7a5fe8d0ab5e2f0da7cc5d8b94572695559d",
  "verdict": "clean",
  "prior": [],
  "findings": []
}

@snyaggarwal
snyaggarwal merged commit 3532fd8 into master Oct 14, 2026
3 checks passed
@snyaggarwal
snyaggarwal deleted the fix/ocl_issues-2911-keep-ocl-org branch October 14, 2026 02:35
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.

oclapi2 resets the OCL org to its seed values on every deploy

2 participants