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

ApiVersion::NullVersion tweaks #615

Merged
merged 2 commits into from
Sep 4, 2019
Merged

ApiVersion::NullVersion tweaks #615

merged 2 commits into from
Sep 4, 2019

Conversation

jtgrenz
Copy link
Contributor

@jtgrenz jtgrenz commented Sep 3, 2019

1. Not strictly a bug, but Session defaults api_version to nil whereas Base defaults it to ApiVersion::NullVersion. For consistency sake, lets keep them the same.

  1. Weird edge case, but if you for some reason stored the value of Base.api_version and then find that version stored, you'd create an ApiVersion called NullVersion. Again, maybe not strictly a bug, but I don't think anyone would intentionally try to find NullVersion and intend to create it. The following example seems like a legit stumbling block, so lets smooth the road so to speak.
ShopifyAPI::ApiVersion.version_lookup_mode
# => :define_on_unknown
ShopifyAPI::Base.api_version
# => ShopifyAPI::ApiVersion::NullVersion
original_version = ShopifyAPI::Base.api_version
ShopifyAPI::Base.api_version = '2019-07'
# => "2019-07"
ShopifyAPI::Base.api_version = original_version
# => ShopifyAPI::ApiVersion::NullVersion
ShopifyAPI::Base.api_version
# => #<ShopifyAPI::ApiVersion:0x00007f835bb2c150 @display_name="ShopifyAPI::ApiVersion::NullVersion", @handle="ShopifyAPI::ApiVersion::NullVersion", @latest_supported=false, @supported=false, @verified=false>

This PR prevents NullVersion from being instantiated and changes find_version to raise if passed the NullVersion class.

@jtgrenz jtgrenz requested a review from nwtn September 3, 2019 19:45
@jtgrenz jtgrenz requested a review from a team as a code owner September 3, 2019 19:45
@nwtn nwtn requested a review from alexaitken September 3, 2019 19:49
@@ -127,11 +127,11 @@ def site
end

def api_version=(version)
@api_version = version.nil? ? nil : ApiVersion.find_version(version)
@api_version = version.nil? ? ApiVersion::NullVersion : ApiVersion.find_version(version)
Copy link
Contributor

Choose a reason for hiding this comment

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

api_version= should work with nil, ApiVersion::NullVersion, any ApiVersion and any String that is in an api version format.

Right now passing in ApiVersion::NullVersion will raise. Making the below code impossible.

session_1= Session.new(domain: domain, url: url, api_version: nil)
session_2 = Session.new(domain: session_1.domain, url: session_1.url, api_version: session_1.api_version)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

guess this is a classic case "if its not broken, don't fix it". Session having a nil version has no negative affects as far as I can tell. Base having a nil version caused us issues, hence the NullVersion. I'll just remove this first commit.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the coercion to out of primitives to ApiVersions is the right move.

This type of change should cover us.

@api_version = ApiVersion::NullVersion.matches?(version) ?  ApiVersion::NullVersion : ApiVersion.find_version(version)




class NullVersion
  def matches?(version)
    version.nil? || version == self
  end
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That sounds like a clean solution to me. Thanks! I just pushed it.

@jtgrenz jtgrenz merged commit 5012b49 into master Sep 4, 2019
@jtgrenz jtgrenz deleted the nullversionbug branch September 4, 2019 20:07
@jtgrenz jtgrenz temporarily deployed to rubygems September 5, 2019 14:13 Inactive
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.

None yet

3 participants