Skip to content

Conversation

@dimitri-yatsenko
Copy link
Member

Summary

Provide helpful error messages when using tables from non-activated schemas.

Problem

When using a table from a non-activated schema, operations produced confusing errors:

schema = dj.Schema()  # Not activated (no database name)

@schema
class TableA(dj.Manual):
    definition = "..."

TableA()  # AttributeError: 'NoneType' object has no attribute 'non_blobs'
TableA().primary_key  # AttributeError: 'NoneType' object has no attribute 'primary_key'

Solution

Override the heading property in Table class to check for None and raise a clear error:

@property
def heading(self):
    if self._heading is None:
        raise DataJointError(
            f"Table `{self.__class__.__name__}` is not properly configured. "
            "Ensure the schema is activated before using the table. "
            "Example: schema.activate('database_name') or schema = dj.Schema('database_name')"
        )
    return self._heading

Before/After

Operation Before After
table.heading AttributeError: 'NoneType'... DataJointError: Table X is not properly configured...
table.primary_key AttributeError: 'NoneType'... DataJointError: Table X is not properly configured...

Test plan

  • Added regression test for non-activated schema heading error

Closes #1039


🤖 Generated with Claude Code

When using tables from non-activated schemas, operations that access
the heading now raise a clear DataJointError instead of confusing
"NoneType has no attribute" errors.

Example:
    schema = dj.Schema()  # Not activated
    @Schema
    class MyTable(dj.Manual): ...

    MyTable().heading  # Now raises: "Table `MyTable` is not properly
                       # configured. Ensure the schema is activated..."

Closes #1039

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@github-actions github-actions bot added bug Indicates an unexpected problem or unintended behavior enhancement Indicates new improvements labels Jan 9, 2026
The heading property now returns None for base tier classes (Lookup,
Manual, Imported, Computed, Part) instead of raising an error. This
allows Python's help() and inspect modules to work correctly.

User-defined table classes still get the helpful error message when
trying to access heading on a non-activated schema.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@dimitri-yatsenko dimitri-yatsenko self-assigned this Jan 9, 2026
@dimitri-yatsenko dimitri-yatsenko merged commit 6c29792 into pre/v2.0 Jan 9, 2026
8 checks passed
@dimitri-yatsenko dimitri-yatsenko deleted the fix/1039-heading-error-message branch January 9, 2026 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Indicates an unexpected problem or unintended behavior enhancement Indicates new improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants