Skip to content

Comments

Add Connection class to enforce explicit Backend connections#337

Merged
JacobHayes merged 1 commit intogoldenfrom
separate-backend-connection
Mar 17, 2023
Merged

Add Connection class to enforce explicit Backend connections#337
JacobHayes merged 1 commit intogoldenfrom
separate-backend-connection

Conversation

@JacobHayes
Copy link
Member

Description

Backend used 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 the MemoryBackend, but will break for almost any other Backend (where the connection actually has some lifecycle).

To enforce this, this PR introduces a new Connection class - which is not a Model - that will wrap the "real" connection and implement the necessary read/write methods.

Additionally, I remove Backend from the serialized fields of Graph to prevent any chance the Backend params (which might include sensitive information) might be serialized with it. The Backend itself is not important for the Graph'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 the Graph object will now loose a handle to the Backend (and then probably default to MemoryBackend?). I don't think we'll copy a Graph much (maybe if it is pickled? 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.

  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How Has This Been Tested?

Updated tests (or rather, fixed some test that previously didn't use backend.connect()!).

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in upstream modules

@JacobHayes
Copy link
Member Author

cc @JamesOswald

@codecov
Copy link

codecov bot commented Mar 16, 2023

Codecov Report

Merging #337 (7f93094) into golden (45fd487) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            golden      #337   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           43        43           
  Lines         2734      2738    +4     
  Branches       690       692    +2     
=========================================
+ Hits          2734      2738    +4     
Impacted Files Coverage Δ
src/arti/backends/__init__.py 100.00% <100.00%> (ø)
src/arti/backends/memory.py 100.00% <100.00%> (ø)
src/arti/executors/__init__.py 100.00% <100.00%> (ø)
src/arti/graphs/__init__.py 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@JacobHayes JacobHayes force-pushed the add-graph-snapshot branch 2 times, most recently from 3644be6 to bd9a5e3 Compare March 16, 2023 14:30
Base automatically changed from add-graph-snapshot to golden March 17, 2023 04:21
@JacobHayes JacobHayes force-pushed the separate-backend-connection branch from 035ad9b to 7f93094 Compare March 17, 2023 04:28
@JacobHayes JacobHayes merged commit bbe5597 into golden Mar 17, 2023
@JacobHayes JacobHayes deleted the separate-backend-connection branch March 17, 2023 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant