首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从部件表(但不是其主表)到上游表的依赖关系突然失败。

从部件表(但不是其主表)到上游表的依赖关系突然失败。
EN

Stack Overflow用户
提问于 2021-04-01 12:29:58
回答 1查看 106关注 0票数 2

我在下游有一张表,其中有一个部件表DownstreamPart。DownstreamPart (而不是下游)依赖于上游表上游(唯一的其他附加依赖是下游)。到目前为止,这个设置已经正常工作了,正确地填充并级联删除了从上游到DownstreamPart的内容,但是现在突然失败了。我得到的错误是:

代码语言:javascript
复制
---------------------------------------------------------------------------
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的后代,没有主表,也没有抛出错误。这两种行为中的哪一种是有意的,我能做些什么来解决我的错误?

编辑i显示在表定义下面,并相应地调整了上面文本中的引用,表定义

代码语言:javascript
复制
@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函数中显示的顺序(正如docstring所说,“输入列表必须按拓扑排序。”但我不知道为什么有时是这样,有时不是拓扑排序)。

我还应该注意到,模式包装在一个自定义模式类中,如下所示:

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

发布于 2021-04-02 14:32:59

嗯,看来表引用可能有问题。您的表实际上以`my_schema`.`B__part`的形式存在,这似乎有点奇怪。在DataJoint Python中,表类应该以CamelCase格式命名。由于数据库(MySQL)支持仅用于小写,因此它将被转换为案例格式。

@lara你能用表格的定义更新你的帖子吗?如果你愿意的话,可以随意使用一个简化的版本。

下面是使用以下示例时发生的情况(DataJoint 0.12.8,python 3.7.3)

代码语言:javascript
复制
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()])

输出:

代码语言:javascript
复制
['`rguzman_my_schema`.`#upstream`', '`rguzman_my_schema`.`~log`', '`rguzman_my_schema`.`b`', '`rguzman_my_schema`.`b__part`']
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66904515

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档