Skip to content

Only wrap ehr_lookups tables whose pseudo-PK differs from the real PK#1168

Open
labkey-martyp wants to merge 2 commits into
release26.3-SNAPSHOTfrom
26.3_fb_ehr_lookups_container_scoping
Open

Only wrap ehr_lookups tables whose pseudo-PK differs from the real PK#1168
labkey-martyp wants to merge 2 commits into
release26.3-SNAPSHOTfrom
26.3_fb_ehr_lookups_container_scoping

Conversation

@labkey-martyp

@labkey-martyp labkey-martyp commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Rationale

This PR fixes ehr_lookups tables whose user-facing key column was hidden and non-insertable in the UI (clinpath_status, project_types, full_snomed, flag_values). The generic fallback in EHRLookupsUserSchema.createTable() wrapped any hard table with a single non-rowid key field and a container column in a ContainerScopedTable, but for tables whose user-facing key is the true DB PK the wrapper is unnecessary — the PK constraint already enforces uniqueness — and its init demoted the key column while the insert path still required a value for it.

Related Pull Requests

None.

Changes

  • Updated the fallback wrapping heuristic to compare the promoted key field against the real PK from JDBC metadata, so only tables where they differ get ContainerScopedTable; tables whose key is the true PK now get CustomPermissionsTable.
  • Tables with composite or missing real PKs are no longer container-scoped, since ContainerScopedTable only supports a single-column real PK.

The generic fallback in EHRLookupsUserSchema.createTable() wrapped any hard table with a single non-rowid key field and a container column in a ContainerScopedTable. For tables whose user-facing key is the true DB PK (clinpath_status, project_types, full_snomed, flag_values), the PK constraint already enforces uniqueness and the wrapper made the key column hidden and non-insertable in the UI. The heuristic now compares the promoted key against the real PK from JDBC metadata, so those tables get CustomPermissionsTable while all 26 rowid-plus-pseudo-PK tables keep container scoping.

Claude-Session: https://claude.ai/code/session_013WM8RcTJDaaopwMTK4H9KX
// and container-scoping such a table made its key column non-insertable in the UI.
String pkColName = getPkColName(ti);
if (pkColName != null && !"rowid".equalsIgnoreCase(pkColName) && ti.getColumn("container") != null)
List<String> realPk = _dbSchema.getTable(name).getPkColumnNames();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

My only question is whether this adds overhead. I suspect that LK might do enough TableInfo caching that this doesnt matter. Second question is whether the TableInfo could be interrogated directly (since it probably stores a reference to the schema table info), rather than calling _dbSchema.getTable(), which would ensure we dont add the overhead of re-querying the DbSchema for that TableInfo.

If you did your own investigation and dont think these issues are worth it, I dont have that strong of an opinion here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, good point on getting the realPk from the existing ti realTable. That change is pushed.

And to your first point, there's nothing here that will re-query the tableinfo metadata. That will already be in the SchemaTableInfoCache. So should be negligible impact on performance.

Addresses PR feedback: the wrapped SimpleTable already holds the source SchemaTableInfo, so read the real PK via getRealTable() (the same idiom ContainerScopedTable.init() uses) rather than resolving the table again through _dbSchema.getTable().

Claude-Session: https://claude.ai/code/session_01YJwkmACfqMmYiAX15YbU1D
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.

2 participants