-
Notifications
You must be signed in to change notification settings - Fork 1.9k
refactor: Remove constance library dependency, use json-encoded model #9852
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
Conversation
posthog/models/constance.py
Outdated
return json.loads(self.raw_value) | ||
|
||
|
||
def get_dynamic_setting(key: str) -> Any: |
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.
q: does constance itself always hit the database? does it not keep anything in memory?
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.
Yes it did - you can see this in tests even.
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.
This looks good overall though I share @yakkomajuri's concerns about naming
posthog/models/constance.py
Outdated
|
||
|
||
@contextmanager | ||
def override_constance_config(key: str, value: Any): |
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.
Actual constance
's override_config()
kwargs
-based approach was super ergonomic IMO, so if this could handle multiple keys at the same time using that API it'd be great (though not a crucial thing)
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.
Agreed - do you consider this a blocker? I discovered this many refactors in, so not looking forward to updating every callsite again.
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.
Not blocking as I don't think we need more-than-single overrides right now, but I can see us doing that in the future, which would result in some ugly nesting, at which point a refactor may be useful
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.
Looks good!
* master: chore: start stack once in cloud tests (#9879) feat(apps): frontend apps (#9831) chore: Fix snapshots on master (#9885) chore(apps): rename plugins to apps (#9755) refactor: Remove constance library dependency, use json-encoded model (#9852) chore(clickhouse): avoid creating kafka_events, events_mv (#9863) fix(insights): Fix timezone date issues (#9678) refactor(plugin-server): refactor the event pipeline (#9829) feat(object storage): add unused object storage (#9846) fix: make kafka health check timeout test reliable (#9857) fix: query elements from start of day (#9827)
…#9852) * Populate the new model * Add constance to admin * Handle table not existing * Add model tests * Add tests for the constance model * Fixup migrations * Update instance settings to use new constance model * update most readings * Use override method in some tests * Improve typing * Prettier * Merge 233 migration * Order imports * Fixup * Update some query counts * Remove dead import * Improve some mypy * Update team.py * Remove constance library * Mark migration as non-atomic * Instance settings cleanup * Rename methods to be more consistent * Fixup for migration * Update tests
Problem
We want to read/write instance settings from plugin-server. Constance using pickle makes that currently unreasonable, so switching to a json-backed model. #9790
Changes
New model + changed callsites for constance usage.
How did you test this code?
See unit tests.