2

我有一个表 Downstream 和一个零件表 DownstreamPart。DownstreamPart,但不是 Downstream,对上游表 Upstream 具有依赖性(唯一的其他附加依赖性是对 Downstream)。到目前为止,此设置一直有效,可以正确填充并级联删除从 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。我的同事使用相同的版本和相同的 datajoint 模式,没有收到此错误。部分表 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)
4

1 回答 1

1

嗯,看起来表格参考可能有问题。您的表实际上以`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`']
于 2021-04-02T14:32:59.813 回答