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

Fix idempotency for publications #85

Merged
merged 1 commit into from
Nov 11, 2021
Merged

Conversation

markgoddard
Copy link

@markgoddard markgoddard commented Nov 10, 2021

If there are multiple publications of a repository version, then the
rpm_publication module will create another, rather than keeping or
updating one of the existing ones.

This happens due to the find() method on PulpEntity looking for
count==1. It uses a limit of one, so only one result is returned, but
the count still gives the full number of matching items, which in this
case is 2.

This change fixes the issue by failing when we cannot find a unique
entity matching the requested parameters.

Fixes: #84

Copy link
Member

@mdellweg mdellweg left a comment

Choose a reason for hiding this comment

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

This is a problem, but i don't think it's safe to assume, that the first one found is the one you want.
The fact that there is no way to identify publications with the same key as you create them is the real problem here for idempotence.
But as your reproducer already shows: If you stay within the world of idempotence (ansible) you cannot produce that situation. So I'd opt for letting the module fail instead of creating a third publication.

if search_result["count"] == 1:
# While we limit to one result, the count may be more than one.
# This may happen if the parameters are not unique, e.g. for a publication.
if search_result["count"] >= 1:
Copy link
Member

Choose a reason for hiding this comment

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

I think we should fail if we find more than one item.

Copy link
Author

Choose a reason for hiding this comment

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

I wondered if you might say this.

Copy link
Member

Choose a reason for hiding this comment

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

At least we agree that creating the third publication is the worst behaviour.

Copy link
Author

Choose a reason for hiding this comment

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

I was 50/50 on which way to go with the solution tbh

Comment on lines 164 to 165
# While we limit to one result, the count may be more than one.
# This may happen if the parameters are not unique, e.g. for a publication.
Copy link
Member

Choose a reason for hiding this comment

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

Can you move that comment to the elif clause, and state that this can happen for models with insufficient or not existing "natural key" (that is how it is called in Django) e.g. Publications.

If there are multiple publications of a repository version, then the
rpm_publication module will create another, rather than keeping or
updating one of the existing ones.

This happens due to the find() method on PulpEntity looking for
count==1. It uses a limit of one, so only one result is returned, but
the count still gives the full number of matching items, which in this
case is 2.

This change fixes the issue by failing when we cannot find a unique
entity matching the requested parameters.

Fixes: pulp#84
elif search_result["count"] > 1:
# While we limit to one result, the count may be more than one.
# This may happen for models with an insufficient or non-existent "natural key"
# e.g. for a publication.
Copy link
Member

Choose a reason for hiding this comment

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

👍 thanks

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.

No idempotency for publications when multiple exist
2 participants