From 62ea6f13743e0e9aa13f8a33b588e27b46e6462f Mon Sep 17 00:00:00 2001 From: Mark <16909269+Archmonger@users.noreply.github.com> Date: Mon, 9 Jan 2023 14:53:55 -0800 Subject: [PATCH] v2.2.1: Fix recursive fetch depth for ManyToOneRel (#117) --- CHANGELOG.md | 10 +++++++++- src/django_idom/__init__.py | 2 +- src/django_idom/utils.py | 11 ++++++----- tests/test_app/components.py | 17 ++++++++++++---- tests/test_app/templates/base.html | 2 +- tests/test_app/tests/js/simple-button.js | 25 ++++++++++++++++++++++++ tests/test_app/tests/test_components.py | 2 +- 7 files changed, 56 insertions(+), 13 deletions(-) create mode 100644 tests/test_app/tests/js/simple-button.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ae0eb0a..ce7c1daa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,13 @@ Using the following categories, list your changes in this order: - Nothing (yet) +## [2.2.1] - 2022-01-09 + +### Fixed + +- Fixed bug where `use_query` would not recursively fetch many-to-one relationships. +- IDOM preloader will now print out the exception stack when failing to import a module. + ## [2.2.0] - 2022-12-28 ### Added @@ -184,7 +191,8 @@ Using the following categories, list your changes in this order: - Support for IDOM within the Django -[unreleased]: https://github.com/idom-team/django-idom/compare/2.2.0...HEAD +[unreleased]: https://github.com/idom-team/django-idom/compare/2.2.1...HEAD +[2.2.1]: https://github.com/idom-team/django-idom/compare/2.2.0...2.2.1 [2.2.0]: https://github.com/idom-team/django-idom/compare/2.1.0...2.2.0 [2.1.0]: https://github.com/idom-team/django-idom/compare/2.0.1...2.1.0 [2.0.1]: https://github.com/idom-team/django-idom/compare/2.0.0...2.0.1 diff --git a/src/django_idom/__init__.py b/src/django_idom/__init__.py index 32c4978c..c1991661 100644 --- a/src/django_idom/__init__.py +++ b/src/django_idom/__init__.py @@ -3,7 +3,7 @@ from django_idom.websocket.paths import IDOM_WEBSOCKET_PATH -__version__ = "2.2.0" +__version__ = "2.2.1" __all__ = [ "IDOM_WEBSOCKET_PATH", "IdomWebsocket", diff --git a/src/django_idom/utils.py b/src/django_idom/utils.py index 0b0d2003..9c76a9f9 100644 --- a/src/django_idom/utils.py +++ b/src/django_idom/utils.py @@ -184,7 +184,7 @@ def _register_components(self, components: set[str]) -> None: _logger.info("IDOM preloader has detected component %s", component) _register_component(component) except Exception: - _logger.error( + _logger.exception( "\033[91m" "IDOM failed to register component '%s'! " "This component path may not be valid, " @@ -236,15 +236,16 @@ def django_query_postprocessor( elif many_to_many and isinstance(field, ManyToManyField): prefetch_fields.append(field.name) + + if prefetch_fields: + prefetch_related_objects([data], *prefetch_fields) + for field_str in prefetch_fields: django_query_postprocessor( - getattr(data, field.name).get_queryset(), + getattr(data, field_str).get_queryset(), many_to_many=many_to_many, many_to_one=many_to_one, ) - if prefetch_fields: - prefetch_related_objects([data], *prefetch_fields) - # Unrecognized type else: raise TypeError( diff --git a/tests/test_app/components.py b/tests/test_app/components.py index 72581aed..29c3da30 100644 --- a/tests/test_app/components.py +++ b/tests/test_app/components.py @@ -1,4 +1,5 @@ import inspect +from pathlib import Path from django.http import HttpRequest from django.shortcuts import render @@ -44,13 +45,21 @@ def parameterized_component(x, y): ) -victory = web.module_from_template("react", "victory-bar", fallback="...") -VictoryBar = web.export(victory, "VictoryBar") +SimpleButtonModule = web.module_from_file( + "SimpleButton", + Path(__file__).parent / "tests" / "js" / "simple-button.js", + resolve_exports=False, + fallback="...", +) +SimpleButton = web.export(SimpleButtonModule, "SimpleButton") @component -def simple_bar_chart(): - return html._(VictoryBar(), html.hr()) +def simple_button(): + return html._( + SimpleButton({"id": "simple-button"}), + html.hr(), + ) @component diff --git a/tests/test_app/templates/base.html b/tests/test_app/templates/base.html index ec99aa1f..ca196297 100644 --- a/tests/test_app/templates/base.html +++ b/tests/test_app/templates/base.html @@ -23,7 +23,7 @@