release-engineering / pubtools-pulplib

A Pulp library for publishing tools
GNU General Public License v3.0
2 stars 24 forks source link

Fix flaky search on 'version' field [RHELDST-12664] #189

Closed rohanpm closed 2 years ago

rohanpm commented 2 years ago

FileUnit.version and ModulemdUnit.version are two fields both named "version", but stored in Pulp in a different way, one of them being top-level and the other stored under pulp_user_metadata.

Previously, the code responsible for generating the pulp search did not take into account exactly what kind of unit is being searched for, and it would end up picking one of the two Pulp fields essentially at random. Fix it to first calculate which unit type is being queried and then use that to resolve the ambiguity.

In cases where criteria remains ambiguous, an error is now raised on search rather than picking one of the fields at random. It could technically be considered a backwards-incompatible change, however any clients currently using such a search might be getting incorrect results at random without realizing it, so it seems best to introduce the check even if it might break some existing code.

codecov[bot] commented 2 years ago

Codecov Report

Merging #189 (a30da57) into master (da8a345) will not change coverage. The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master      #189   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           48        48           
  Lines         2929      2964   +35     
=========================================
+ Hits          2929      2964   +35     
Impacted Files Coverage Δ
pubtools/pulplib/_impl/client/errors.py 100.00% <100.00%> (ø)
pubtools/pulplib/_impl/client/search.py 100.00% <100.00%> (ø)
pubtools/pulplib/_impl/criteria.py 100.00% <100.00%> (ø)
pubtools/pulplib/_impl/model/unit/base.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us.