-
Notifications
You must be signed in to change notification settings - Fork 189
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
StorageBackend
: Remove recreate_user
from _clear
#5772
StorageBackend
: Remove recreate_user
from _clear
#5772
Conversation
1999ee0
to
453a0c0
Compare
Thanks @sphuber , makes sense.
Are there any other users of |
Currently not, but I imagine at some point this would become the generic entry point to clear a database when a profile is deleted. The profile delete functionality is currently still hardcoded to the psql-dos backend in |
994eabc
to
586f2cd
Compare
The `_clear` method on the `StorageBackend` deletes all data in the storage. This is used by the unit tests when a test requires a clean storage to test against. However, the ORM assumes that a `User` instance, designated by the profile as the default user, is always present. As soon as an ORM entity is stored that requires a user but that is not explicitly defined, the default user is retrieved. When a new profile is configured, the setup command ensures that the default user is properly created. However, when the storage is cleared, the user is also deleted and so it needs to be recreated. This job had been assigned to the `StorageBackend` but really this should not be its responsibility. It is specific to the use case of the test cases that reset the storage and need to reconstruct the user, so it should take care of that. The `recreate_user` argument is removed from `StorageBackend._clear` and the logic to recreate a user after storage reset is moved to the `ProfileManager`. The `clear_profile` method, which calls the storage clear, recreates the user at the end. The `TemporaryProfileManager`, which subclasses the `ProfileManager` does the same when a temporary test profile is created at the start of a test session.
586f2cd
to
20a312e
Compare
@ltalirz is there anything you still wanted to check here? |
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.
Currently not
Ok, just wanted to be sure that we're not changing behavior that some other place relies on. In that case, good to go!
The
_clear
method on theStorageBackend
deletes all data in the storage. This is used by the unit tests when a test requires a clean storage to test against. However, the ORM assumes that aUser
instance, designated by the profile as the default user, is always present. As soon as an ORM entity is stored that requires a user but that is not explicitly defined, the default user is retrieved.When a new profile is configured, the setup command ensures that the default user is properly created. However, when the storage is cleared, the user is also deleted and so it needs to be recreated. This job had been assigned to the
StorageBackend
but really this should not be its responsibility. It is specific to the use case of the test cases that reset the storage and need to reconstruct the user, so it should take care of that.The
recreate_user
argument is removed fromStorageBackend._clear
and the logic to recreate a user after storage reset is moved to theProfileManager
. Theclear_profile
method, which calls the storage clear, recreates the user at the end. TheTemporaryProfileManager
, which subclasses theProfileManager
does the same when a temporary test profile is created at the start of a test session.