Skip to content

fix: copy order actions in prefetch so querysets can be re-executed - #1825

Open
moneebullah25 wants to merge 2 commits into
ormar-orm:masterfrom
moneebullah25:fix/prefetch-order-by-reuse
Open

moneebullah25 wants to merge 2 commits into
ormar-orm:masterfrom
moneebullah25:fix/prefetch-order-by-reuse

Conversation

@moneebullah25

Copy link
Copy Markdown

Fixes #1818

LoadNode mutated the shared OrderAction objects (is_source_model_order, table_prefix) while building prefetch queries, so executing the same queryset a second time with prefetch_related + order_by on a related field gave wrong results. The order action is now copied before it is modified.

Changes:

  • ormar/queryset/queries/prefetch_query.py: copy.copy the order action before mutating it.
  • tests/test_relations/test_prefetch_related.py: regression test that runs the same queryset twice.

Checks run:

  • ruff format --check and ruff check on the changed files: clean

  • mypy --ignore-missing-imports on the changed files: no issues

  • pytest tests/test_relations/test_prefetch_related.py tests/test_queries: 112 passed

  • Tests added for the change

  • Linting and type checks run on changed files

  • Docs updated (not applicable)

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

Re-running a queryset with prefetch_related and order_by on the related field fails on the second execution

1 participant