Skip to content

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

Merged
merged 28 commits into from
May 20, 2022

Conversation

macobo
Copy link
Contributor

@macobo macobo commented May 19, 2022

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.

@macobo macobo marked this pull request as ready for review May 19, 2022 11:02
@macobo macobo requested review from yakkomajuri and tiina303 and removed request for yakkomajuri May 19, 2022 11:02
@macobo macobo changed the title refactor: (WIP) Remove constance library dependency, use json-encoded model refactor: Remove constance library dependency, use json-encoded model May 19, 2022
@neilkakkar
Copy link
Contributor

neilkakkar commented May 19, 2022

Quick flyby that the API call from the frontend doesn't yet work

image

return json.loads(self.raw_value)


def get_dynamic_setting(key: str) -> Any:
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Member

@Twixes Twixes left a 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



@contextmanager
def override_constance_config(key: str, value: Any):
Copy link
Member

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)

Copy link
Contributor Author

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.

Copy link
Member

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

@macobo macobo requested a review from Twixes May 20, 2022 09:24
Copy link
Member

@Twixes Twixes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@macobo macobo merged commit 3412eed into master May 20, 2022
@macobo macobo deleted the kill-constance branch May 20, 2022 12:12
fuziontech added a commit that referenced this pull request May 20, 2022
* 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)
alexkim205 pushed a commit that referenced this pull request May 23, 2022
…#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
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.

4 participants