Restricting a dj.U() aggregation raises a bare AssertionError
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 40/100
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
- Langage dominant
- Python
- Étoiles
- 197
- Forks
- 99
- Merge moyen
- 2 j 10 h
- PR mergées (30 j)
- 12
Préparer son environnement
- Fournit un Dockerfile ou un fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de datajoint/datajoint-python
-
MySQL error 1143 (column-level SELECT denied) is not translated to AccessErrorPeut-être pris @Bhanu73120 l’a pris il y a 3 jours. Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 85/100
datajoint/datajoint-python#1586 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
datajoint/datajoint-python#1581 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
datajoint/datajoint-python#1539 · 3 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Environment variables lose to datajoint.json for settings missing from ENV_VAR_MAPPINGPeut-être pris @dimitri-yatsenko l’a pris il y a 3 jours. Ouverte
datajoint/datajoint-python#1585 · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
-
_job_start_time records the populating host's local time, with no zonePeut-être pris @dimitri-yatsenko l’a pris il y a 4 jours. Ouverte
datajoint/datajoint-python#1584 · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de datajoint/datajoint-python
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
omegaup/omegaup#10353 · 1 commentaire ·
Les mainteneurs répondent en général sous 5 jours
-
bot-triaged module: LrScheduler module: optimizer triaged
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
Les mainteneurs répondent en général sous 1 jour
-
documentation glm5 llm-model
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
vllm-project/vllm-ascend#19062 ·
Les mainteneurs répondent en général sous 1 jour
-
Author Page: shuai-zhao-llmOuverteauthor-page correction
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
acl-org/acl-anthology#10496 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour