-
Notifications
You must be signed in to change notification settings - Fork 67
SWIFT-957 Fill in namespace on invalidate events #519
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
Conversation
| /// using the decoder e.g. `ChangeStreamEvent` to access the namespace even if it is not present in the raw | ||
| /// document the server returns. Ok to force unwrap as initialization never fails. | ||
| // swiftlint:disable:next force_unwrapping | ||
| internal let changeStreamNamespaceKey = CodingUserInfoKey(rawValue: "namespace")! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ideally this would have lived on ChangeStream, but you can't have stored static properties on generic types 🤔
| ) | ||
| self.client = client | ||
| self.decoder = decoder | ||
| self.decoder = BSONDecoder(copies: decoder, options: nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we are updating the userInfo I figured it was a bit safer to make a copy.
this did make me think about the fact that right now users can't give us userInfo that we should use when decoding their custom types, even though they can configure all of the other encoder/decoder options via the strategies. I don't think that's too urgent though, we can wait until if/when someone asks for this capability.
| self.ns = try container.decode(MongoNamespace.self, forKey: .ns) | ||
| } catch { | ||
| guard let ns = decoder.userInfo[changeStreamNamespaceKey] as? MongoNamespace else { | ||
| throw error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered just filling in with an empty namespace or something here, but that seemed like it would hide errors from the server in cases where a namespace is unexpectedly missing.
patrickfreed
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like LinuxMain needs to be synced, but other than that LGTM!
|
someday I'll actually remember to sync it 🤦♀️ I should probably set up a githook |
Codecov Report
@@ Coverage Diff @@
## master #519 +/- ##
==========================================
- Coverage 77.87% 77.64% -0.23%
==========================================
Files 129 130 +1
Lines 13787 13860 +73
==========================================
+ Hits 10736 10762 +26
- Misses 3051 3098 +47
Continue to review full report at Codecov.
|
|
@patrickfreed it turns out that on 3.6 the behavior is slightly different when a collection is dropped; there is no |
This PR works around the fact that invalid events do not have associated namespaces by accepting a
MongoNamespaceinChangeStream.init, and then storing that namespace undernsin theChangeStream'sBSONDecoder'suserInfo.ChangeStreamEventthen looks for the matching key when decoding, and falls back to it if there is no key present in the original document.Per conversation in driver-devs it appears that as of now anyway it's impossible to encounter an invalidate event on a client.