如何解决从部分表而不是其主表到上游表的依赖突然失败
我有一个表 Downstream 和一个零件表 DownstreamPart。下游部分,但不是下游,依赖于上游表上游(唯一的其他附加依赖是下游)。到目前为止,此设置一直有效,可以正确填充并级联从 Upstream 到 DownstreamPart 的删除,但现在突然失败了。我得到的错误是:
---------------------------------------------------------------------------
DataJointError Traceback (most recent call last)
<ipython-input-6-17abf9cc6c8e> in <module>
----> 1 (TrainedModel() & dict(dataset_hash="464e47555aae42ee0ee6edd980dd66ad")).delete()
~/.local/lib/python3.7/site-packages/datajoint/table.py in delete(self,verbose)
415 delete_list = OrderedDict(
416 (name,_RenameMap(next(iter(graph.parents(name).items()))) if name.isdigit() else FreeTable(conn,name))
--> 417 for name in graph.descendants(self.full_table_name))
418
419 # construct restrictions for each relation
~/.local/lib/python3.7/site-packages/datajoint/dependencies.py in descendants(self,full_table_name)
147 nx.algorithms.dag.descendants(self,full_table_name))
148 return unite_master_parts([full_table_name] + list(
--> 149 nx.algorithms.dag.topological_sort(nodes)))
150
151 def ancestors(self,full_table_name):
~/.local/lib/python3.7/site-packages/datajoint/dependencies.py in unite_master_parts(lst)
28 break
29 else:
---> 30 raise DataJointError("Found a part table {name} without its master table.".format(name=name))
31 return lst
32
DataJointError: Found a part table `my_schema`.`downstream__part` without its master table.
我有 DJ 版本 0.12.8 和 Python 版本 3.7.5。 我的同事使用相同的版本和相同的数据联合架构,没有收到此错误。零件表 B_part 正确显示为表 A 的后代,没有其主表,也没有抛出错误。 这两种行为中的哪一种是预期的,我可以做些什么来解决我的错误?
编辑 我在表格定义下方显示并相应地调整了上面文本中的引用 表定义
@my_schema
class Upstream(dj.Computed):
deFinition = """
-> further_upstream
---
upstream_attribute: int
"""
class UpstreamStorage(dj.Part):
deFinition = """
-> master
---
stored_attrib: attach@store
"""
@my_schema
class Downstream(dj.Manual):
deFinition = """
-> other_dependency
"""
class DownstreamPart(dj.Part):
deFinition = """
-> master
-> Upstream
"""
我还发现这有时会失败,有时会起作用,这取决于表在 unite_master_part
函数中显示的顺序(如文档字符串所说,“输入列表必须按拓扑排序。”;但是不知道为什么有时是这样,有时又不是拓扑排序的)。
class CustomSchema(Schema):
def __call__(self,cls,*,context=None):
context = context or self.context or inspect.currentframe().f_back.f_locals
# Process all part tables and replace with a subclass
for attr in dir(cls):
if attr[0].isupper():
part = getattr(cls,attr)
if inspect.isclass(part) and issubclass(part,dj.Part):
class WrappedPartTable(part):
pass
WrappedPartTable.__name__ = attr
setattr(cls,attr,WrappedPartTable)
return super().__call__(cls,context=context)
解决方法
嗯,看起来表引用可能有问题。您的表实际上以 `my_schema`.`B__part`
的形式存在,这似乎有点奇怪。在 DataJoint Python 中,表类应该以 CamelCase 格式命名。由于数据库 (MySQL) 支持仅支持小写,因此将其转换为 snake_case 格式。
@lara 你会用所涉及的表的定义更新你的帖子吗?如果您愿意,可以随意使用简化版。
这是使用以下示例时发生的情况 (DataJoint 0.12.8
,python 3.7.3
)
import datajoint as dj
schema = dj.Schema('rguzman_my_schema')
@schema
class Upstream(dj.Lookup):
definition = """
upstream_id: int
---
upstream_name: varchar(30)
"""
contents = [(0,'joe')]
@schema
class B(dj.Manual):
definition = """
b_id: int
---
b_name: varchar(30)
"""
class Part(dj.Part):
definition = """
-> Upstream
---
b_part_name: varchar(30)
"""
# Display how the tables are actually represented in the database.
# In DataJoint Python `0.13.0`,it can now be easily called using
# `schema.list_tables()`
print([t['table_name'] for t in dj.conn().query(
"""
SELECT CONCAT('`',table_schema,'`.`',table_name,'`') AS table_name
FROM information_schema.tables
WHERE table_schema = %s""",args=('rguzman_my_schema',),as_dict=True).fetchall()])
输出:
['`rguzman_my_schema`.`#upstream`','`rguzman_my_schema`.`~log`','`rguzman_my_schema`.`b`','`rguzman_my_schema`.`b__part`']
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。