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

make UnparsedVersion.__lt__ order-agnostic #8559

Merged
merged 3 commits into from
Sep 6, 2023
Merged

Conversation

MichelleArk
Copy link
Contributor

@MichelleArk MichelleArk commented Sep 5, 2023

resolves #8571
docs dbt-labs/docs.getdbt.com/#

Problem

The current implementation of UnparsedVersion.__lt__ is sensitive to the order of arguments, leading to surprising behaviour such as:

>>> from dbt.contracts.graph.unparsed import UnparsedVersion
>>> UnparsedVersion(12) < UnparsedVersion("2")
True
>>> UnparsedVersion(12) > UnparsedVersion("2")
True

The root cause is that UnparsedVersion.lt first attempts to cast self.v to other's type in order to do the comparison, and if that fails then attempts to cast other.v to self type. This means that casting may work in some directions but not others and result in different comparison methods (e.g. numeric vs alphabetic) depending on which input is self and which is other.

Solution

UnparsedVersion.v is either float or str. Simplify the lt implementation to just try to cast both inputs to floats and do a numeric comparison, falling back to str if this is not posssible -- making the method insensitive to order but more tightly coupled to the type of UnparsedVersion.v

Checklist

  • I have read the contributing guide and understand what's expected of me
  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • This PR has no interface changes (e.g. macros, cli, logs, json artifacts, config files, adapter interface, etc) or this PR has already received feedback and approval from Product or DX

@cla-bot cla-bot bot added the cla:yes label Sep 5, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Sep 5, 2023

Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the contributing guide.

@codecov
Copy link

codecov bot commented Sep 5, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (a0e1356) 86.37% compared to head (4c20c35) 86.37%.
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8559   +/-   ##
=======================================
  Coverage   86.37%   86.37%           
=======================================
  Files         174      174           
  Lines       25587    25582    -5     
=======================================
- Hits        22100    22096    -4     
+ Misses       3487     3486    -1     
Flag Coverage Δ
integration 83.17% <100.00%> (+<0.01%) ⬆️
unit 65.06% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
core/dbt/contracts/graph/unparsed.py 93.43% <100.00%> (+0.31%) ⬆️

... and 2 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MichelleArk MichelleArk marked this pull request as ready for review September 6, 2023 20:08
@MichelleArk MichelleArk requested a review from a team as a code owner September 6, 2023 20:08
@MichelleArk MichelleArk merged commit 89f20d1 into main Sep 6, 2023
51 checks passed
@MichelleArk MichelleArk deleted the fix-unparsed-version-lt branch September 6, 2023 21:47
github-actions bot pushed a commit that referenced this pull request Sep 6, 2023
@aranke aranke mentioned this pull request Jul 12, 2024
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CT-3084] [Bug] UnparsedVersion.__lt__ is sensitive to order
3 participants