Read JSON::Any Columns as .to_json'd String#467
Open
jon-sully wants to merge 1 commit intoamberframework:masterfrom
Open
Read JSON::Any Columns as .to_json'd String#467jon-sully wants to merge 1 commit intoamberframework:masterfrom
.to_json'd String#467jon-sully wants to merge 1 commit intoamberframework:masterfrom
Conversation
Member
|
Thanks for bringing this to my attention. I hadn't gotten notice of any PR's put on this repo, so I'm sorry about the late reply! I'll have to dig into this more because I want to expand how Granite handles types and help improve it. Have you joined our Discord yet? https://discord.gg/vwvP5zakSn |
Member
|
Closed by accident. Ultimately this sounds like the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Greetings 👋
Submitting this small PR as I recently ran into an issue when using
importfor a model. If I created the model one-off and used.new(add attribute values) then.save, the model would save just fine. If I instead set up a bunch of models then used.import, I'd get an error that stemmed down to this issue.The short of it is that each adapter's
import(pg's here) callsread_attributeunder the hood and passes the then-read value along to the query builder but does so with its native type. If you ask a model for the value of aJSON::Any-typed column, you'll get aJSON::Anytyped value. The query builder doesn't like that type though and will error.This PR injects a
.to_jsonin the process for any column whose type includesJSON::Any. This does indeed convert the value to a string and makes the query builder happy, but this PR may well be a proof of concept. There is definitely a better way of doing this, and this may overall be a stop-gap where correctly wiring up the Granite Converter(s) could be the right choice. Submitting this to explain my story, give some context, and hopefully inspire a better path forward!Cheers!