Skip to content

fix: make SessionBlock.Trial a part table so importing acquisition doesn't create one - #218

Draft
tabedzki wants to merge 2 commits into
masterfrom
tabedzki/fix/session-block-trial-part
Draft

tabedzki wants to merge 2 commits into
masterfrom
tabedzki/fix/session-block-trial-part

Conversation

@tabedzki

@tabedzki tabedzki commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

🤖 AI text below 🤖

Fixes #217

Problem

#186 added SessionBlockTrial as a top-level dj.Imported class. DataJoint resolves that to _session_block_trial, which isn't in the database, so importing u19_pipeline.acquisition tried to create it. With a SELECT-only account the error is swallowed; with an account that can create tables, any import would leave an empty stray table.

Comparison

SessionBlock trial table resolves to
U19-pipeline-matlab (9675625) dj.Imported SessionBlockTrial, dj.Part _session_block__trial
Database _session_block _session_block__trial
Python before #186 not defined not defined
Python since #186 dj.Imported SessionBlockTrial, dj.Imported _session_block_trial (doesn't exist)
This PR dj.Imported SessionBlock.Trial, dj.Part _session_block__trial

Both tables stay defined in Python: _towers_block has a foreign key to _session_block, and _towers_block__trial has one to _session_block__trial.

Fix

 acquisition.SessionBlock
+  class Trial(dj.Part):  -> master, trial_idx
-acquisition.SessionBlockTrial (dj.Imported)
 behavior.TowersBlock.Trial
-  -> acquisition.SessionBlockTrial
+  -> acquisition.SessionBlock.Trial

Evidence

  • Before (1b3512ee): pytest tests/test_table_definitions.py → 3 failed, 1 passed ('_session_block_trial' == '_session_block__trial').
  • After: 4 passed. Full suite: 780 passed, 7 skipped (no database, or extras not installed). uvx prek run --all-files passes.
  • Against the database, with a SELECT-only account and a guard that blocks writes: before, importing the module issued CREATE TABLE ... _session_block_trial. After, it issues no write, and all four tables resolve to existing ones.

The new tests need no database. They import the table modules with unactivated schemas.

Merge Danger

Door: two-way

Blast Radius: low. Nothing else in the repo used SessionBlockTrial. No table in the database changes.

Second fix: Session.stimulus_set

#186 also added stimulus_set : tinyint to acquisition.Session. The live u19_acquisition.session table has no such column, Python did not declare it before #186, and MATLAB's Session.m declares it but its insert code never sets it. Reads were unaffected (DataJoint takes an existing table's heading from the database; a fetch on 21cad340 works). This PR removes that one line. behavior.TowersSession.stimulus_set is a real column and is unchanged. All other columns in the tables #186 and this PR touched were compared with the live schema; names, types, keys and parent tables match. The database's nullable DEFAULT 0 columns (main_level, trial_duration_median, is_bad_block) can't be expressed exactly in DataJoint and stay as they are, matching MATLAB.

  • Before (21cad340): the new test_session_does_not_declare_stimulus_set fails (stimulus_set found in Session.definition); the other 5 tests in tests/test_table_definitions.py pass.
  • After (d5dfc919): 6 passed in that file. Full suite: 782 passed, 7 skipped. uvx prek run --all-files passes.

Assisted-by: ClaudeCode:claude-opus-5-5
Assisted-by: ClaudeCode:claude-sonnet-5-5

…esn't create one

#186 added SessionBlockTrial as a top-level dj.Imported class, which DataJoint
resolves to `_session_block_trial`. The table in the database is the part
table `_session_block__trial` (a dj.Part in U19-pipeline-matlab), so importing
u19_pipeline.acquisition tried to declare a new one.

Define it as the part SessionBlock.Trial, and point TowersBlock.Trial at it.

Assisted-by: ClaudeCode:claude-opus-5-5
…Session

#186 added stimulus_set to acquisition.Session, but the live
u19_acquisition.session table has no such column and MATLAB never fills it.
Reads were unaffected, because DataJoint takes an existing table's heading
from the database; the definition was just wrong. behavior.TowersSession's
stimulus_set is a real column and stays. Add DB-free tests for both.

Assisted-by: ClaudeCode:claude-sonnet-5-5
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.

[BUG] Importing acquisition tries to CREATE a stray _session_block_trial table

1 participant