-
Notifications
You must be signed in to change notification settings - Fork 85
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
JSONB + empty default bug #535
Comments
Thanks for the fantastic write up! 👏👏👏 This is the issue I will point to when people ask what they should do to document a bug. Thank you so much. Also it seems like you found the source of the problem, which helps. I'm not sure what the fix is and don't have much (any?) context on AR internals around this stuff, but hey this is a learning opportunity and seems like a real bug so I'll see if I can figure out what's going on. |
So the problem is this line:
Removing it "fixes" the bug (but of course also renders the backend unusable). |
I think #536 fixes the issue, and also simplifies the code quite a lot. Give it a try. |
@shioyama thanks for the immediate response! The branch passed on our CI and I found no issues when playing with it in console. Trying it required to revert our workaround with dropping the default and |
I need to finally release 1.3.0 which includes this, but based on what I've seen in other PRs on master it seems like this will cause some breakage. People make PRs to So far I've been releases patches on 1.2 but this is getting difficult so I need to finally ship 1.3... |
I'd release 2.x and add a notice for devs to double check JSONB columns has a default One should be careful though, because in between running a migration which adds the default value and reloading your application with the fix, the bug with Even if deploying as one commit, you can't run the migration and reload your application at the very same moment. But I guess it's still better to maintain "migration + gem update" order (and deal with |
Yeah, I'm thinking of releasing a |
Ok this has finally been released as 1.3.0.rc1. Sorry about the delay! Hopefully it won't cause too many issues updating for folks using jsonb/hstore backends. |
Any update on releasing 1.3 stable? |
1.3.0 has been released |
When a JSONB column has empty default (
{}
) as suggested, and it is wrapped with Mobilitytranslates
, reading from that column messes up ActiveRecord's dirty tracking. After you read from that column,changes
starts reporting very confusing diff (no writes were performed):This is not related to the Mobility's dirty tracking plugin as removing/disabling it does not fix the behavior.
Context
https://gist.github.com/nashbridges/764f5da35d1a4f13eb98fccf647ef8b2
We use Postgres 13.2.
Expected Behavior
All tests should pass.
Actual Behavior
I have two failing tests:
The second failure is interesting, because it shows that by not providing the
{}
default for the DB column we can get the desired behavior: there's nonil
related errors +changes
is not mutated. For now this is what we do in our application (dropping the default) as a workaround.Possible Fix
I was able to track down the source of the issue to different column type.
When there's no
translates
the JSONB column is handled by the JSONB type, which treats the default correctly.When the column is wrapped with
translates
it is handled by the Serialized type, which somehow returnsnil
for a default value case.It's not clear though what would be the fix.
The text was updated successfully, but these errors were encountered: