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

BAI-1299 Python semantic versioning bugfix #1305

Merged
merged 6 commits into from
Jun 11, 2024

Conversation

bw27492
Copy link
Member

@bw27492 bw27492 commented Jun 3, 2024

  • Semantic versons containing 'v' will no longer break client

@bw27492 bw27492 requested review from GB27247 and a3957273 June 3, 2024 16:39
@version.setter
def version(self, value):
if isinstance(value, str):
version_obj = value.replace("v", "")
Copy link
Member

Choose a reason for hiding this comment

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

This replaces all v characters throughout the string. Which could be within the build or the pre-release. Instead use

version_obj = value.removeprefix("v")

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Copy link
Member Author

@bw27492 bw27492 Jun 5, 2024

Choose a reason for hiding this comment

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

Update - this was added in 3.9 so fails our Python 3.8 tests :( have changed to an older method

raise TypeError("Provided version not of a supported type.")

self._version_obj = version_obj
self._version_raw = value
Copy link
Member

Choose a reason for hiding this comment

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

Here it's probably better to fetch from the object rather than the value. In this method coerce is used however this is not used on the backend validation. so will fail with strings like '0.1.2.3.4'

Copy link
Member Author

Choose a reason for hiding this comment

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

The _version_raw attribute is the same value used to get/create releases on the server - so if the user inputs an incorrect value the server will return an error anyway. Also if we get the semver from the object, the v will have been removed so if the user calls .update() the server won't find the right release (e.g. the client will try to get 2.0.0 as opposed to v2.0.0)

return self._version_obj

@version.setter
def version(self, value):
Copy link
Member

Choose a reason for hiding this comment

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

I would put this validation in post_release as well within the create classmethod just to prevent an unnecessary response when creating that endpoint.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think we want to fully stop users from adding the 'v' using the post_release method, as the front and backend will allow this. It only presented an issue when creating the Version() object which is used to compare Release() objects etc, which is resolved with this PR whilst allowing the user to include the 'v' upon creation if they want to

Comment on lines +280 to +281
@version.setter
def version(self, value):
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 it's best to make this private. Just to avoid any problematic updating.

Copy link
Member Author

@bw27492 bw27492 Jun 6, 2024

Choose a reason for hiding this comment

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

Done - alternative fix for this. If the user tries to set the version after it has already been defined, it will throw a BailoException. Making the attribute itself private caused larger issues in the code base and created a breaking change

@bw27492 bw27492 merged commit c70b26b into main Jun 11, 2024
16 checks passed
@bw27492 bw27492 deleted the BAI-1299-python-semantic-version-bugfix branch June 11, 2024 12:34
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.

2 participants