-
-
Notifications
You must be signed in to change notification settings - Fork 61
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
Nippy doesn't know how to freeze metadata from next.jdbc #171
Comments
@slipset Hi Erik, I'm sorry but I'm not 100% sure what you're asking exactly. If you want to drop the metadata from an object in Clojure, you can use Alternatively, you could disable I hope that helps? |
It might be because I'm not 100% sure what I'm asking :)
As for the implementation of this protocol, we see it here So, to what I'm asking for, envisioning:
Again, sorry if this should have been obvious to me :) |
Reading about |
Okay, gotcha - thanks for clarifying. And I guess next.jdbc doesn't allow you to disable this metadata from its side (or you sometimes do use this metadata)? I'd avoid using If you're looking for a very easy solution, it'd probably be better to globally turn off
This is where I'd lean. There's a few options for how to approach this, depending on the details of what next.jdbc is doing. I'm unfortunately not familiar with the library, but basically, you'll want to use E.g. if the troublesome metadata consists of a limited number of specific types, you could configure Nippy to no-op on these types, e.g.:
That'll basically intercept the relevant metadata as it's being serialized, so that it gets serialized as Having said that - I'd actually be keen to understand better whether it might be useful for Nippy to automatically skip the relevant types out-the-box. Would be happy to take a look at a PR. Or I can take a look at doing this myself if you (or someone else) could point me to (and/or provide a simple example I can play with) that shows the relevant info re: what specific result and metadata types are involved. Is the result metadata always unserializable? |
Thanks again for coming back to me. I'll loop in @seancorfield so he can shed some light on this as well. The metadata in question should (I believe) not be serialized, as it's used for interacting with tools like REBL (which I believe is now called something else) to visually browse result sets. I do think the Having said that, I don't think this next.jdbc metadata ever makes sense to serialize over nippy, as they are basically closures, so if I'm not mistaken, it would be impossible to thaw them in any meaningful way. |
Here's some more info: #:clojure.core.protocols{datafy
#function[next.jdbc.result-set/navize-row/fn--31316],
nav
#function[next.jdbc.result-set/navable-row/fn--31319]} So I guess it's the |
So, being slow, I'm sorry. But it just occurs to me. Protocol implementations doesn't make sense to serialize, because, well functions. And I guess what we're seeing here is an effect of protocols being attachable to metadata as of Clojure 1.10/1.11? |
Functions are never going to be serializable which means Nippy is never going to be able to handle any objects that implement protocols via metadata. I'm not at my computer yet to check, but do functions implement |
Should be sufficient to check if something is a function, and skip it if it is? |
Thanks for your input on this Sean 🙏
Interesting, I'm not familiar with Datafy nor metadata protocol extension - both had slipped by my radar.
The problem is that we don't want to just silently skip arbitrary fns in general. If someone's trying to serialize a fn, it may be by ignorance or an accident - in which case the current behaviour (throwing) is appropriate to indicate that an unfreezable type was encountered. It might be reasonable to make an exception in the specific case though of top-level fn vals in metadata due to metadata protocol extension. Will look into this properly next time I'm on batched Nippy work (certainly before end of this month) - want to understand better what problem metadata protocol extension is meant to solve, how widely it's used, etc. @slipset What's your level of urgency on this? |
None :) We've worked around this for some time and can deffo do so for some |
Allows serialization of next.jdbc results, etc.
The ability to extend protocols via metadata was added in Clojure 1.10, about six years ago, so that users could make arbitrary data satisfy specific protocols without needing to specifically extend the protocol. It's primarily used to allow certain hash maps to participate in protocol functions -- rather than trying to extend the protocol to all hash map data types -- and you'll see it used quite a bit in applications that use Component (Sierra's lib). I don't know how widespread its use is with Note that, with In all of these cases, the metadata will include keys that are fully-qualified symbols (identifying a function from some protocol) and a value that is a function to be used as the implementation of that protocol, and that could occur at any nesting "level" within any data structure. And, now I'm at a computer, in answer to my own question: yes, Clojure functions are marked as |
@seancorfield Hi Sean, thanks for the detailed info - that's very helpful and much appreciated! 🙏 I've modified Nippy master to auto strip
Thanks for clarifying this. That won't be a problem, Nippy's freezing is recursive - so we need only define the behaviour for metadata maps in general, and that'll automatically apply to metadata at any nesting level.
Correct, though that's not a problem - Nippy already tests for |
Allows serialization of next.jdbc results, etc.
@slipset Hi Erik- this should now be addressed in v3.4.0-RC3. If you get an opportunity, please let me know if that works for you? I'm aiming to cut the final release by end of this month. Thanks again for pinging about this! Cheers :-) |
Works like a charm, it seems :) We seem to have nippy as a transitive dep on carmine (at 3.2.0) Would it be okay to just explicitly depend on nippy 3.4.0? |
You're very welcome, thanks for the fast confirmation.
Yes, that would be fine. Any time I update Carmine, I'll always bump to the latest stable Nippy version. Just be aware that if you're freezing data with Nippy vX, you should always thaw with Nippy >= vX otherwise you may run into exceptions while thawing. I.e. if you do update Nippy on nodes that write to Redis, make sure you also update it on nodes that read from Redis. Also, depending on your risk profile - you may want to wait for v3.4.0 stable at the end of this month. |
This is most likely me not reading the docs well enough, but:
next.jdbc attaches metadata to its results which nippy doesn't know how to serialize, and nippy then throws.
I would be more than happy if I could instruct nippy to just disregard this metadata.
The text was updated successfully, but these errors were encountered: