fix: stop default_tags from one client leaking into other clients' WriteApi#710
Open
arpitjain099 wants to merge 1 commit into
Open
fix: stop default_tags from one client leaking into other clients' WriteApi#710arpitjain099 wants to merge 1 commit into
arpitjain099 wants to merge 1 commit into
Conversation
The write_api() factories and WriteApi.__init__ used PointSettings() as a default argument value, so every call that omitted point_settings shared one PointSettings instance created at function-definition time. _BaseWriteApi then mutated that shared instance in place with the client's default_tags, which caused one client's default_tags to leak into every other client's WriteApi, including clients with no default_tags of their own. The async path had the identical bug. Change the four point_settings defaults from PointSettings() to None and build a fresh PointSettings in _BaseWriteApi when none is supplied. Add a regression test asserting no cross-client leak. Closes influxdata#686 Signed-off-by: arpitjain099 <arpitjain099@gmail.com>
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.
Closes #686
Proposed Changes
The write_api factories and the WriteApi/WriteApiAsync constructors defaulted point_settings to PointSettings(). Mutable default, so the same instance is shared across calls that omit it, and _BaseWriteApi.init mutates it in place when the client has default_tags. So one client's default_tags leak into other clients' write APIs, even ones that set none. Same thing on the async path.
Did what the issue suggested: default the four point_settings args to None and create a fresh PointSettings in _BaseWriteApi.init when it's None. Also dropped the now-unused PointSettings imports.
Added a regression test (plain client, then a client with default_tags, then reuse the plain client and check its tags are still empty). Fails on main, passes with the fix. flake8 clean.
Checklist