Add Connection class to enforce explicit Backend connections#337
Merged
JacobHayes merged 1 commit intogoldenfrom Mar 17, 2023
Merged
Add Connection class to enforce explicit Backend connections#337JacobHayes merged 1 commit intogoldenfrom
JacobHayes merged 1 commit intogoldenfrom
Conversation
Member
Author
|
cc @JamesOswald |
Codecov Report
@@ Coverage Diff @@
## golden #337 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 43 43
Lines 2734 2738 +4
Branches 690 692 +2
=========================================
+ Hits 2734 2738 +4
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
3644be6 to
bd9a5e3
Compare
Signed-off-by: Jacob Hayes <[email protected]>
035ad9b to
7f93094
Compare
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.
Description
Backendused to implement all of the read/write methods directly, but in reality these should be called with a connection to the database, not just the spec referencing the database. This would allow code to accidentally call these methods without explicitly connecting. This works ok with theMemoryBackend, but will break for almost any otherBackend(where the connection actually has some lifecycle).To enforce this, this PR introduces a new
Connectionclass - which is not aModel- that will wrap the "real" connection and implement the necessary read/write methods.Additionally, I remove
Backendfrom the serialized fields ofGraphto prevent any chance theBackendparams (which might include sensitive information) might be serialized with it. TheBackenditself is not important for theGraph's output: we pull the necessary (meta)data out from the Backend when snapshotting. The one edge case this might introduce is that any (deep)copy of theGraphobject will now loose a handle to theBackend(and then probably default toMemoryBackend?). I don't think we'll copy aGraphmuch (maybe if it ispickled? Still not sure we'd want to store the creds then either), but it may be worth looking out for.Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Updated tests (or rather, fixed some test that previously didn't use
backend.connect()!).Checklist: