-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
MONGOID-5078 Fix shard_key_selector_in_db during post-persist callbacks - DRAFT #4991
base: master
Are you sure you want to change the base?
Conversation
I am converting this PR to "non-draft mode" because it won't assign reviewers otherwise. |
@dalton-braze |
@johnnyshields, would you be able to clarify your suggestion? How I'm parsing it, I'm not seeing how changing the point-in-time that The key section of this PR is the following updated method: def shard_key_selector_in_db
selector = {}
shard_key_fields.each do |field|
selector[field.to_s] = new_record? || during_post_persist_callbacks ? send(field) : attribute_was(field)
end
selector
end If my explanation feels ambiguous, I'd suggest checking out the repro test cases I've written in As for how |
@dalton-braze sorry my comment was mistaken, please ignore. |
@comandeo this might be a good one for you to look at given your expertise with |
@johnnyshields @dalton-braze The issue seems to be fixed here - 9fa2cc3 I think we can close this PR. |
@comandeo can we merge in just the tests from this PR? (or tests that demonstrate the fix, in other words) |
@comandeo mind taking a look here again and deciding if we could close this one? |
@Neilshweky the problem here is certainly a legitimate one for users who use sharding. Ticket should be kept open. |
Hi @p and @comandeo,
The mongoid#4985 PR allowed me to tweak my existing solution draft for MONGOID-5078 because of
shard_key_selector_in_db
being split out ofshard_key_selector
.shard_key_selector_in_db
is defined as:This supports the conclusion that
shard_key_selector_in_db
should contain the updated version of a shard key during "post-persist" callbacks (after_create
,after_save
,after_update
,after_upsert
, etc). The current incorrect behavior is thatshard_key_selector_in_db
returns the old value of a shard key during "post-persist" callbacks which are triggered by updating a shard key.The potential solution I designed adds a single instance variable,
@during_post_persist_callbacks
, to eachMongoid::Document
. This instance variable is read byshard_key_selector_in_db
to determine if it should return a sharded field's internally cached previous value or its current value.This PR is intended as a draft (especially the example tests I wrote). I am hoping to use it as a jumping-off point for discussing the solution to this behavior in more detail. I'd love to hear what you think.
For a much deeper level of detail, check out my original open PR here.