When asked for a decision, Greenwave returns multiple results or waivers when verbose==True in case the same "subject" gets repeated. Removing duplicated waivers and results.
This address that: https://github.com/fedora-infra/bodhi/issues/3089
Why insert duplicate items to verbose_* lists in the first place?
verbose_*
BTW, retrieve_latest method doesn't use cache so the duplicate invocation is needlessly expensive.
retrieve_latest
I'm not sure you can actually know they are the same element until you make the request... We could check the subject_identifier. But we could also have 2 waivers for the same subject_identifier (different product versions). Can we have 2 waivers for the same subject_identifier and product_version but different subject_type? I dunno.
We could for sure don't repeat the request if all 3 are the same. But I think the user shouldn't make this kind of request in the first place if the subjects are the same element... and also: "subject" parameter is deprecated and people should just stop using it.
I think this is a OK quick fix. The ultimate goal should be stop supporting "subject" in favor of "subject_identifier" and "subject_type". But we have to make a major release of the API for that.
OK, but can you use set instead of list? The "removing duplicated elements" code doesn't look very nice.
set
I agree with @lholecek to use set instead of list. If you need to preserve order you can use ordered_set.
list
ordered_set
rebased onto 1f5194dfd14406458819ff0b58947c0aef66d3e9
You cannot set() on a list of dict because dict is not hash-able. I've put another version. Is it fine now?
Oh, I forgot that dict isn't hashable. Otherwise this looks much better.
dict
return list({item['id']: item for item in items}.values())
+1
I like this approach as well. It's a lot easier to read.
rebased onto eac7149f0c1229daa60de87155c34e3ef7356566
rebased onto 9c60a0e91659ab4ace5831c808b861ccb56e8faf
All comments should be addressed and conflicts resolved. @mprahl @lholecek another review? Thank you.
I can see trailing underscore in r_ variable name in other already existing tests, but it should not be used for new tests, or does the trailing _ have any special meaning?
r_
_
It should/could be possible cleared for all other tests in a separate PR.
@gnaponie, looks good, just a minor comment there... Tests are passing for the PR?
Mmm not sure why it is like that in other tests. I prefer "r_" instead of "r" because if you use the debugger (pdb) and try to check "r" it actually "returns" (because it is a debugger command) and that's annoying...
I've tried once again and they pass on my local machine.
Hint: you can use p r in the debugger
p r
Commit ea4a93e8 fixes this pull-request
Pull-Request has been merged by gnaponie
When asked for a decision, Greenwave returns multiple results or
waivers when verbose==True in case the same "subject" gets repeated.
Removing duplicated waivers and results.