Restricting a dj.U() aggregation raises a bare AssertionError
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 40/100
調査の方向性
The failing assertion is in Aggregation.make_sql in expression.py near line 1358, and the PostgreSQL subquery gate uses _grouping_attributes; read condition.py for the no-common-attributes restriction semantics. First reproduce with dj.U().aggr(File, n="count(*)") & "n = 3" on MySQL. Done when the assertion is gone, the HAVING and subquery paths both return correct rows on MySQL and PostgreSQL, and tests cover string and dict restrictions with matching and non-matching counts plus restricting another table.
索引モデルが issue の本文から書いたものです。
説明
Restricting a universal aggregation, dj.U().aggr(...) & <condition>, raises an AssertionError with no message, on any backend. The aggregation itself returns the expected single row; only the restriction fails, including when the restricted aggregate is used to restrict another table.
Versions: v2.3.4 and master at 68fdea59, MySQL 8.0.
Reproduction
@schema
class File(dj.Manual):
definition = """
file_id : int32
---
filename : varchar(255)
"""
File.insert([(1, "a_part1.dat"), (2, "a_part2.dat"), (3, "a_meta.json")])
total = dj.U().aggr(File, n="count(*)")
total.to_dicts() # [{'n': 3}]
(total & "n = 3").to_dicts() # AssertionError
(total & {"n": 3}).to_dicts() # AssertionError
len(File & (total & "n = 3")) # AssertionError
Expected: (total & "n = 3") returns [{'n': 3}] (and [] when the count differs), and File & (total & "n = 3") keeps every row of File when the restricted aggregate is non-empty and none when it is empty, as restriction by an expression with no common attributes does elsewhere (condition.py, "without common attributes, any non-empty set matches everything").
Cause
Aggregation.make_sql (expression.py:1358):
assert self._grouping_attributes or not self.restriction
A restriction on an aggregation is emitted as HAVING (MySQL) or as an outer WHERE around a subquery (PostgreSQL), but both paths assume grouping attributes exist. The PostgreSQL branch is also gated on them (use_subquery_for_having = ... and self._grouping_attributes).
Proposed fix
- Remove the assertion.
- MySQL: emit
HAVINGwithoutGROUP BY, which MySQL accepts for an ungrouped aggregate and which may reference the select alias (SELECT count(*) AS n FROM t HAVING n = 3). - PostgreSQL: take the existing subquery path whenever the aggregation is restricted, with or without grouping attributes.
- Tests: restrict
dj.U().aggr(T, n="count(*)")by a string and by a dict, on both backends, with matching and non-matching counts; and restrict another table by the restricted aggregate.
Workaround
Wrap the aggregate in a subquery before restricting it:
gate = dj.U().aggr(File, n="count(*)").make_subquery() & {"n": 3}
File & gate # all rows when the count is 3, none otherwise
len(gate) still fails on this form; see the companion issue on len() of an expression with an empty primary key.
- 主要言語
- Python
- スター
- 197
- フォーク
- 98
- 平均マージ
- 15時間 31分
- マージ済み PR(30日)
- 9
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
datajoint/datajoint-python のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
datajoint/datajoint-python#1581 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
datajoint/datajoint-python#1539 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
database.name should namespace schema names on MySQL, as it does on PostgreSQL対応中かも @dimitri-yatsenko が 3 日前に担当しました。 オープンfeature
難易度 4/5 3〜5日 初心者へのやさしさ 15/100
datajoint/datajoint-python#1582 ·
メンテナーはふだん 1 日以内に返信
-
A column copied by a foreign key loses the parent's core type (int32 becomes int)対応中かも @dimitri-yatsenko が 3 日前に担当しました。 オープン
難易度 3/5 半日 初心者へのやさしさ 25/100
datajoint/datajoint-python#1578 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 半日 初心者へのやさしさ 65/100
datajoint/datajoint-python#1577 ·
メンテナーはふだん 1 日以内に返信
datajoint/datajoint-python の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
spec-kitty/spec-kitty#6112 ·
メンテナーはふだん 1 日以内に返信
-
[Bug]: OpenRouter streaming chunks report the requested router name instead of the model OpenRouter served対応中かも @Mrun25 が今日担当しました。 オープンbug llm translation
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
BerriAI/litellm#46095 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
uberdeveloper/fastbt#29 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
andrew-blake/melcloudhome#368 ·
メンテナーはふだん 1 日以内に返信
-
lane:discover
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
SPARDiffData/differential-data-collection#33 ·
メンテナーはふだん 1 日以内に返信