You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: Tables with AttributeAdapter columns raise AssertionError: Declaration context is not set #1278
Tables with AttributeAdapter columns raise AssertionError: Declaration context is not set on attempting to drop and when used as foreign keys. This seems to be because context is not passed down from origin table to FreeTable when it is created internally
This issue is resolved in DataJoint 2.0 by replacing the AttributeAdapter system entirely with a new Codec system.
Root Cause
The legacy AttributeAdapter required a "declaration context" (the Python module where the table was defined) to resolve custom type adapters. When DataJoint internally created FreeTable objects for dependency tracking and foreign key resolution, it failed to pass this context, causing the AssertionError.
2.0 Architecture
DataJoint 2.0 introduces a new Codec system that eliminates context dependencies:
# Define a custom codec (auto-registers on subclass)classGraphCodec(dj.Codec):
name="graph"# Used as <graph> in definitionsdefget_dtype(self, is_external: bool) ->str:
return"<blob>"defencode(self, graph, *, key=None, store_name=None):
return {'nodes': list(graph.nodes()), 'edges': list(graph.edges())}
defdecode(self, stored, *, key=None):
importnetworkxasnxG=nx.Graph()
G.add_nodes_from(stored['nodes'])
G.add_edges_from(stored['edges'])
returnG# Use in table definitions with angle bracket syntaxclassConnectivity(dj.Manual):
definition=''' id : int --- graph_data : <graph> '''
Why This Fixes the Issue
Legacy AttributeAdapter
2.0 Codec System
Context-dependent resolution
Global codec registry
Required module inspection
Auto-registration on subclass
FreeTable context issues
No context dependency
Decorator-based registration
Automatic via __init_subclass__
The architectural flaw that caused this issue no longer exists - codecs are looked up from a global registry (_codec_registry) rather than requiring module context to be passed through the call chain.
Migration
Replace AttributeAdapter subclasses with Codec subclasses:
Implement get_dtype(), encode(), and decode() methods
Activity
dimitri-yatsenko commentedon Dec 22, 2025
Solved in #1289
dimitri-yatsenko commentedon Jan 8, 2026
DataJoint 2.0 Solution
This issue is resolved in DataJoint 2.0 by replacing the
AttributeAdaptersystem entirely with a new Codec system.Root Cause
The legacy
AttributeAdapterrequired a "declaration context" (the Python module where the table was defined) to resolve custom type adapters. When DataJoint internally createdFreeTableobjects for dependency tracking and foreign key resolution, it failed to pass this context, causing theAssertionError.2.0 Architecture
DataJoint 2.0 introduces a new Codec system that eliminates context dependencies:
Why This Fixes the Issue
AttributeAdapterCodecSystem__init_subclass__The architectural flaw that caused this issue no longer exists - codecs are looked up from a global registry (
_codec_registry) rather than requiring module context to be passed through the call chain.Migration
Replace
AttributeAdaptersubclasses withCodecsubclasses:get_dtype(),encode(), anddecode()methodsnameclass attribute<name>syntax in table definitionsSee PR #1289 for the full implementation.
dimitri-yatsenko commentedon Jan 9, 2026
Resolved in DataJoint 2.0
The AttributeAdapter system has been replaced by the new Codec architecture in DataJoint 2.0.
Migration path:
AttributeAdapters should be migrated to Codecs:
Before (AttributeAdapter):
After (Codec):
Benefits of Codec system:
__init_subclass__The specific bug with declaration context is not applicable to the new Codec system.
See the migration guide for detailed migration instructions.