datajoint-python
datajoint-python copied to clipboard
Inconsistent handling of errors for non-activated `UserTable`s
Bug Report
Description
Calling class methods, properties, or instance methods derived from parent classes of UserTable
creates inconsistent and confusing error messages when schema is not activated for a set of tables.
import datajoint as dj
dj.config["loglevel"] = "INFO"
schema = dj.Schema()
@schema
class TableA(dj.Manual):
definition = """
# TableA example
table_a : UUID
---
label : VARCHAR(100)
"""
# printing of some properties is ok:
print(TableA.definition) # ok -> No error.
# # TableA example
# table_a : UUID
# ---
# label : VARCHAR(100)
# Error description is valid for these cases:
TableA().describe() # ok -> DataJointError: Class TableA is not properly declared (schema decorator not applied?)
TableA.describe() # ok -> DataJointError: Class TableA is not properly declared (schema decorator not applied?)
# Uninformative error:
TableA() # bad -> AttributeError: 'NoneType' object has no attribute 'non_blobs'
# Additional situations of inconsistent errors when printing from an non-activated `Table`.
@schema
class TableB(dj.Manual):
definition = """
thing : INT
----
label : VARCHAR(200)
"""
instance = TableB()
# ok -> no error
print(TableB.definition)
# thing : INT
# ---
# label : VARCHAR(200)
# preview.py:51, AttributeError: 'NoneType' object has no attribute 'non_blobs'
instance
# condition.py:154, AttributeError: 'NoneType' object has no attribute 'names'
instance & {}
# expression.py:96, AttributeError: 'NoneType' object has no attribute 'primary_key'
instance.fetch("KEY")
# expression.py:96, AttributeError: 'NoneType' object has no attribute 'primary_key'
instance.head()
TableB.head()
# condition.py:75, AttributeError: 'NoneType' object has no attribute 'secondary_attributes'
TableB & TableA
# issues with `__repr__`` and `_repr_html_`
# preview.py:8, AttributeError: 'NoneType' object has no attribute 'non_blobs'
instance.head
TableB.head
dj.config["loglevel"] = "DEBUG"
# ok -> <bound method QueryExpression.head of <__main__.TableB object at 0x1231b3cd0>>
instance.head
# diff error than before (closer to indication about activation) -> # expression.py:96, AttributeError: 'NoneType' object has no attribute 'primary_key'
instance.head()
Thanks for the report @iamamutt! :handshake:
This does seem like unintentional behavior although it doesn't seem like it would be too much to patch.