Skip to content

[PULP-1777] Fix postgres 65k param limit on the Copy API - #1506

Open
pedro-psb wants to merge 1 commit into
pulp:mainfrom
pedro-psb:fix/error-with-postgres-65k-limit
Open

[PULP-1777] Fix postgres 65k param limit on the Copy API#1506
pedro-psb wants to merge 1 commit into
pulp:mainfrom
pedro-psb:fix/error-with-postgres-65k-limit

Conversation

@pedro-psb

@pedro-psb pedro-psb commented Aug 19, 2026

Copy link
Copy Markdown
Member

This uses the same approach used in pulp_rpm with query param growth-rate based tests. It's an alternative approach to #1499

Basically, we record every query within the unit test using django utilities, do some data treatment, hook in python's inspect module and we get traceable code (in points where querysets are evaluated) to generated SQL, plus some sql metadata. And among that metadata is query params count.

The test uilities themselves can be improved, but it already catches the bulk of scenarios which can potentially trigger this param limit error. Plus an experimental n+1 detector 👀 (which you didn't have in copy! apparently at least, congratz)


  • Add growth rate based tests
  • Fix linear SQL params count growth rate in copy API
  • Add n+1 detector test for copy API and fixes for some of them

Assisted-By: Claude Sonnet 5

📜 Checklist

  • Commits are cleanly separated with meaningful messages (simple features and bug fixes should be squashed to one commit)
  • A changelog entry or entries has been added for any significant changes
  • Follows the Pulp policy on AI Usage
  • (For new features) - User documentation and test coverage has been added

See: Pull Request Walkthrough

@pedro-psb

Copy link
Copy Markdown
Member Author

Look at this comment to see some samples of how that new test machinery works: pulp/pulp_rpm#4538 (comment)

I plan to extract those test utilities somehwere, maybe pulpcore, but IHO it's not a big deal to duplicate it here.
Also, I'd like encourage you to play with it, it might help improving queries on some hot paths.

@pedro-psb

Copy link
Copy Markdown
Member Author

There was a test hanging, I'll investigate it tomorrow.

@pedro-psb
pedro-psb marked this pull request as draft August 20, 2026 10:52
@pedro-psb
pedro-psb force-pushed the fix/error-with-postgres-65k-limit branch from 55ffb0c to 690e8ca Compare August 20, 2026 15:36
@pedro-psb

pedro-psb commented Aug 20, 2026

Copy link
Copy Markdown
Member Author

SQL Diff (filtered by call made from within find_structured_publish_content for a specific growth profile, forget which one):
https://gist.github.com/pedro-psb/b7781af0b3309c02ea784c4f475a0b32

And a nice read about unnest/arrays (although it talks about inserts, it explains well how the idea behind it in general):
https://www.tigerdata.com/blog/boosting-postgres-insert-performance

@pedro-psb
pedro-psb force-pushed the fix/error-with-postgres-65k-limit branch from 690e8ca to d7135f5 Compare August 20, 2026 17:32
@pedro-psb
pedro-psb marked this pull request as ready for review August 20, 2026 17:34
* Add growth rate based tests
* Fix linear SQL params count growth rate in copy API
* Add n+1 detector test for copy API and fixes for some of them

Assisted-By: Claude Sonnet 5
@pedro-psb
pedro-psb force-pushed the fix/error-with-postgres-65k-limit branch from d7135f5 to 4e28ab5 Compare August 20, 2026 17:37
IgnoreFromPath(
pattern=r"pulp_deb/app/models/repository\.py:\d+ in handle_duplicate_releases",
reason="needs further investigation on real impact",
),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've skipped dealing with this to avoid doing too many real plugin changes in one PR.

If you remove this ignore item and run the unit test you'll see exactly what ORM call is causing a N+1 and you can view the SQL report with the snippet (the unit test error output should be informative enough).

oci-env exec cat /tmp/pytest-artifacts/test_query_count_is_size_invariant.packages_across_distributions.small.sql

I had a quick look and the cause for this N+1 is that the code queries Content filtering by releases, and inside a loop you call release.distribution, which triggers a new Release query call per item to fetch the corresponding distribution.

@pedro-psb pedro-psb changed the title Fix postgres 65k param limit on the Copy API [PULP-1777] Fix postgres 65k param limit on the Copy API Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant