Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combining with django-reversion #56

Closed
Natureshadow opened this issue Jun 5, 2022 · 2 comments
Closed

Combining with django-reversion #56

Natureshadow opened this issue Jun 5, 2022 · 2 comments

Comments

@Natureshadow
Copy link

I am trying to use django-cte on models managed with reversion. When running createinitialrevisions, it seems that the correct QuerySet or manager is not used:

  File "/home/lukas/.cache/pypoetry/virtualenvs/aleksis-core-yiBKpV3N-py3.10/lib/python3.10/site-packages/reversion/management/commands/createinitialrevisions.py", line 66, in handle
    live_objs = _safe_subquery(
  File "/home/lukas/.cache/pypoetry/virtualenvs/aleksis-core-yiBKpV3N-py3.10/lib/python3.10/site-packages/reversion/models.py", line 389, in _safe_subquery
    left_query = left_query.annotate(**{exist_annotation_name: models.Exists(right_subquery)})
  File "/home/lukas/.cache/pypoetry/virtualenvs/aleksis-core-yiBKpV3N-py3.10/lib/python3.10/site-packages/django/db/models/query.py", line 1091, in annotate
    return self._annotate(args, kwargs, select=True)
  File "/home/lukas/.cache/pypoetry/virtualenvs/aleksis-core-yiBKpV3N-py3.10/lib/python3.10/site-packages/django/db/models/query.py", line 1130, in _annotate
    clone.query.add_annotation(
  File "/home/lukas/.cache/pypoetry/virtualenvs/aleksis-core-yiBKpV3N-py3.10/lib/python3.10/site-packages/django_cte/query.py", line 49, in add_annotation
    super(CTEQuery, self).add_annotation(annotation, *args, **kw)
  File "/home/lukas/.cache/pypoetry/virtualenvs/aleksis-core-yiBKpV3N-py3.10/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1039, in add_annotation
    annotation = annotation.resolve_expression(self, allow_joins=True, reuse=None,
  File "/home/lukas/.cache/pypoetry/virtualenvs/aleksis-core-yiBKpV3N-py3.10/lib/python3.10/site-packages/django_cte/expressions.py", line 45, in resolve_expression
    for cte in get_query(clone)._with_ctes:
AttributeError: 'Query' object has no attribute '_with_ctes'

I cannot really wrap my head around it; apart from running the management command, everything works fine.

Maybe someone who knows about how django-cte uses custom QuerySets can help understand the issue?

@Natureshadow
Copy link
Author

This appears to be #46.

@millerdev
Copy link
Contributor

Fixed by #60

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants