-
Notifications
You must be signed in to change notification settings - Fork 0
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
setup_notification command #2
Conversation
d6a2708
to
a68eabb
Compare
Welcome to Codecov 🎉Once merged to your default branch, Codecov will compare your coverage reports and display the results in this comment. Thanks for integrating Codecov - We've got you covered ☂️ |
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 think it makes more sense to run all phases of a step and only then move to the next step, so that you can sort out dependencies between steps.
Now the order of steps is irrelevant since you first check all pre-requisites, then run all configurations and then the self tests but that breaks if you have a step that requires another step to be completed first
if prerequisites are missing | ||
""" | ||
missing = [ | ||
var for var in self.required_settings if not getattr(settings, var, None) |
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.
What if a valid setting value is None
? Is that a case to consider?
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.
How should I interpret these required settings? Can you give an example?
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.
Hmm I can't make up an example when we need None
as a valid setting for configuration. But False
can definitely be a valid one, so I'll refactor it.
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.
You can find an example in Open Zaak - https://github.com/open-zaak/open-zaak/blob/4b870e709f1c08d53464eb6b76bc7ace11b2d87a/src/openzaak/config/bootstrap/demo.py#L29
Here we configure a demo user. So if settings with demo credentials are missing, then we raise PrerequisiteFailed
If we want to skip this step we can set DEMO_CONFIG_ENABLE = False
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 guess if it can be None, its not required?
if not self.enable_setting: | ||
return True | ||
|
||
return getattr(settings, self.enable_setting, True) |
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.
Do we really need to do this via a Django setting step? Why can't we directly point to the name of an envvar and skip having to define a Django setting that reads the envvar?
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 use django settings to set defaults when it's possible. For example we can have a default for SELECTIELIJST_API_ROOT
|
||
class ConfigurationRunFailed(ConfigurationException): | ||
""" | ||
Raise an error then configuration process was faulty |
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.
s/then/when?
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.
changed
@@ -0,0 +1,117 @@ | |||
from collections import OrderedDict |
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.
Python dicts retain insertion order, you generally don't need OrderedDict anymore
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.
TIL! Changed to dict
|
||
class Command(BaseCommand): | ||
help = ( | ||
"Bootstrap the initial Open Zaak configuration. " |
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.
Probably should remove Open Zaak from this docstring
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.
Removed :)
django_setup_configuration/management/commands/setup_configuration.py
Outdated
Show resolved
Hide resolved
Co-authored-by: Sergei Maertens <[email protected]>
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.
To be honest I haven't considered case when one configuration step can be dependent on the other.
I thought of step.validate_requirements
function more like a check that all required environment variables are provided. This is why I wanted first to check prerequisites of all the steps and give a full list of missing variables to the user.
I can do it step by step, but it can be annoying for the user.
Or I can divide this check into two parts: check required env vars and check other dependencies, and the latter can be done step by step.
if prerequisites are missing | ||
""" | ||
missing = [ | ||
var for var in self.required_settings if not getattr(settings, var, None) |
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.
Hmm I can't make up an example when we need None
as a valid setting for configuration. But False
can definitely be a valid one, so I'll refactor it.
if prerequisites are missing | ||
""" | ||
missing = [ | ||
var for var in self.required_settings if not getattr(settings, var, None) |
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.
You can find an example in Open Zaak - https://github.com/open-zaak/open-zaak/blob/4b870e709f1c08d53464eb6b76bc7ace11b2d87a/src/openzaak/config/bootstrap/demo.py#L29
Here we configure a demo user. So if settings with demo credentials are missing, then we raise PrerequisiteFailed
If we want to skip this step we can set DEMO_CONFIG_ENABLE = False
if not self.enable_setting: | ||
return True | ||
|
||
return getattr(settings, self.enable_setting, True) |
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 use django settings to set defaults when it's possible. For example we can have a default for SELECTIELIJST_API_ROOT
|
||
class ConfigurationRunFailed(ConfigurationException): | ||
""" | ||
Raise an error then configuration process was faulty |
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.
changed
@@ -0,0 +1,117 @@ | |||
from collections import OrderedDict |
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.
TIL! Changed to dict
|
||
class Command(BaseCommand): | ||
help = ( | ||
"Bootstrap the initial Open Zaak configuration. " |
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.
Removed :)
@sergei-maertens thank you for the review! |
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.
Just needs Django 4.2 support so it won't hold us back in migrating projects.
@joeribekker Django 4.2 is supported now |
fixes #1