Skip to content
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

Serialize the panels #1826

Closed

Conversation

tim-schilling
Copy link
Member

This is a draft PR. I'm keeping my on-going work in this branch. I found that my efforts to close #1807 and #1808 quickly spiraled into a major refactor of core logic.

This currently handles the SQLPanel which required the following changes:

  • Drop raw_params entirely. We'll need to serialize the parameters every time now so we can't rely on the original params
  • Refactor the SQL queries to use a djdt_query_id which uniquely identifies each query. The SQL forms now reference this id and avoid passing SQL to be executed.
  • Move the formatting logic of SQL queries back to just before rendering. Otherwise we're rendering and storing the html in the store (I could be convinced I'm over-engineering for the future)

In addition this also changed our design for Panel

  • load_stats_from_store - Generates a Panel instance with the passed in data.
  • Panel.panel_id is now a class member to avoid needing to instantiate a panel to programatically get the panel id. With the new focus on fetching data for a specific panel given its ID, this became more of a need

tim-schilling and others added 5 commits August 20, 2023 21:23
This matches the new naming defined in the store module and will make
things eaiser to change moving forward.

This will break anything using the store internally causing issues for
third party packages.
The remainder of the work is to fix the individual panels' serialization errors.
This avoids needing to create an instance of a panel to get its
panel ID.
@tim-schilling
Copy link
Member Author

I think this is at a point where we can add some async tests to confirm that this approach will work or not.

Copy link
Member

@matthiask matthiask left a comment

Choose a reason for hiding this comment

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

Thanks!

  • I like the change from store IDs to request IDs.
  • It's nice that we no longer accept SQL strings from the client and execute them (even with signing)

I'm not totally sure, is this (somewhat) backwards compatible for third party panels? This wouldn't be an argument against it, just something to clarify.

tests/panels/test_sql.py Show resolved Hide resolved
@tim-schilling
Copy link
Member Author

is this (somewhat) backwards compatible for third party panels?

While it doesn't break any documented APIs for the panel to function itself, this version is not backwards compatible since it loads the content for the panel from the store (render_panel view). That will need to be made backwards compatible to make this generally backwards compatible.

@tim-schilling
Copy link
Member Author

@matthiask I'm back to forcing everything that can't be serialized to JSON to a str. Otherwise we're trying to do it manually per panel which will involve a function that's likely going to do similar object and collection iteration as json.dumps().

tim-schilling and others added 6 commits August 28, 2023 19:08
The alternative here is to inspect and iterate over every collection and
object passed around. This avoids having to reinvent the wheel in that
scenario.
* Add note on lack of async support to Installation docs
* Add note on lack of async support to the Readme

#1828 (comment)
updates:
- [github.com/adamchainz/django-upgrade: 1.14.0 → 1.14.1](adamchainz/django-upgrade@1.14.0...1.14.1)
- [github.com/pre-commit/mirrors-prettier: v3.0.1 → v3.0.2](pre-commit/mirrors-prettier@v3.0.1...v3.0.2)
- [github.com/pre-commit/mirrors-eslint: v8.47.0 → v8.48.0](pre-commit/mirrors-eslint@v8.47.0...v8.48.0)
- [github.com/astral-sh/ruff-pre-commit: v0.0.284 → v0.0.286](astral-sh/ruff-pre-commit@v0.0.284...v0.0.286)
- [github.com/tox-dev/pyproject-fmt: 0.13.1 → 1.1.0](tox-dev/pyproject-fmt@0.13.1...1.1.0)
- [github.com/abravalheri/validate-pyproject: v0.13 → v0.14](abravalheri/validate-pyproject@v0.13...v0.14)
Any instance attributes shouldn't be used because they can't be
relied upon for historical purposes. Especially when it comes to
the titles and nav titles.
@tim-schilling tim-schilling marked this pull request as ready for review September 5, 2023 01:27
@tim-schilling
Copy link
Member Author

This assumes we'll have some shared memory store for the cache hence the change to should_render_panels

pre-commit-ci bot and others added 12 commits September 26, 2023 07:17
* panels(templates): postpone context processing

- this makes it show evaluated querysets which were used in the template
- removes completely context processing when SHOW_TEMPLATE_CONTEXT is
  disabled

* panels(templates): avoid evaluating LazyObject

LazyObject is typically used for something expensive to evaluate, so avoid evaluating it just for showing it in the debug toolbar.
* Add Python 3.12 to the test matrix.

* Allow pre-releases for setup actions with GitHub actions.

* Skip unnecessary test for python 3.12

* Update docs/changes.rst

Co-authored-by: Matthias Kestenholz <[email protected]>

---------

Co-authored-by: Matthias Kestenholz <[email protected]>
tim-schilling and others added 21 commits July 3, 2024 11:06
Only when the user is customizing both the show toolbar callback
setting and the URLs aren't installed will the underlying
NoReverseMatch error occur.
While this isn't a huge improvement, it provides a hook for us
to more easily introduce library level controls for when urls
are installed. It also eliminates the user from having to
write an if statement for the most basic of installations.
…ng (#1933)

* Fixed issue #1682 -- alert user when using file field without proper encoding

* Changed issues to alerts, added docstring to check_invalid_... function, changed call in nav_subtitle to get_stats

* Update AlertsPanel documentation to list pre-defined alert cases

* added check for file inputs that directly reference a form, including tests; also added tests for setting encoding in submit input type

* Update the alert messages to be on the panel as a map.

This also explicitly mentions what attribute the form needs in
the message.

* Expose a page in the example app that triggers the alerts panel.

---------

Co-authored-by: Tim Schilling <[email protected]>
* Use css properties for height and width
…1946)

* Check for for StreamingHttpResponse when generating stats in Alert
panel.
- Add jinja2 template to example app.
- Switch to the render function to include context.

It instruments the single template render, but not the inherited
templates and I'm guessing not the included templates either.
I suspect we're going to have to patch jinja templates more robustly
than relying on the django jinja backend template class.

Co-Authored-By: Tim Schilling <[email protected]>
Now that we're using the actual jinja template backend,
it only instruments a single template.
* fixed order and grammatical number of panels in documentation
* updated changes.rst to reflect change to docs
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.5.0 → v0.5.1](astral-sh/ruff-pre-commit@v0.5.0...v0.5.1)
- [github.com/tox-dev/pyproject-fmt: 2.1.3 → 2.1.4](tox-dev/pyproject-fmt@2.1.3...2.1.4)
The alerts panel may eventually have other types of alerts that
don't depend on the response. Such as Django's check system.
@tim-schilling
Copy link
Member Author

tim-schilling commented Jul 10, 2024

I messed this PR up. I meant to do the merge into serializable then rebase this. If the tests pass here, I'll push it to serializable.

tim-schilling and others added 5 commits July 10, 2024 08:44
The stats must be stored as JSON, otherwise it'll be
converted to a string.
This causes problems with tests and changing the settings
via override_settings. Since we're using the lru_cache
decorator on get_config, there's very little benefit to
caching within the store too.
The majority were difficulities with caching and settings.
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.