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

Avoid hash with default values due to inconsistent marshaling #932

Merged
merged 2 commits into from
Oct 17, 2017

Conversation

maximebedard
Copy link
Contributor

Encoding/Decoding the liquid context using different encoders doesn't always encode hashes and remember that they can have a default value.

# Poor example, but `snappy` would behave the same way.
irb(main):009:0> JSON.load(JSON.dump(Hash.new(0)))[0]
=> nil # => 0 would have been expected

Instead, it's easier to just avoid using default values here and simply cast them to Fixnum where needed.

@fw42
Copy link
Contributor

fw42 commented Sep 20, 2017

I don't understand the context of this patch. What problem does this solve? This seems a bit like a workaround for a bug in some other piece (that has nothing to do with Liquid).

@dylanahsmith
Copy link
Contributor

What is the use case for serializing and deserializing the context? I know we experimented with serializing and deserializing parsed templates to avoid parsing overhead, but I don't see why we would care about that for the context.

If we were going to care about the context being serializable, then we should have a test for that.

Copy link
Contributor

@pushrax pushrax left a comment

Choose a reason for hiding this comment

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

👍 to this change but I'd also like to hear more about why you need this.

@dylanahsmith
Copy link
Contributor

He explained the context out of band. Basically this is needed for fragment caching, since we would need to cache register changes and apply them when using the cached fragment.

@maximebedard
Copy link
Contributor Author

Sorry getting back to this after a little while. Would it make sense to ship this PR as it currently is and then build integration tests that make sure the Liquid context is fully serializable/deserializable or simple unit test that assert the hash has no defaults would suffice?

@dylanahsmith
Copy link
Contributor

build integration tests that make sure the Liquid context is fully serializable/deserializable or simple unit test that assert the hash has no defaults would suffice?

Basically we want a test that avoids a regression in whatever we are doing on top of liquid. So if that code is serializing and deserializing the whole context, then that would be more appropriate to do in a test to avoid that regression. Having a test that checks that the register value to make sure it is a hash without defaults overly coupled to the implementation and wouldn't test as much, so it would be easier to introduce a regression somewhere else in the context.

Would it make sense to ship this PR as it currently is and then

Sure, feel free to :shipit: to unblock your work.

@maximebedard maximebedard merged commit 7d2d90d into master Oct 17, 2017
@maximebedard maximebedard deleted the avoid-default-values-hash branch October 17, 2017 20:02
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

4 participants