Skip to content

Commit 62ea6f1

Browse files
authored
v2.2.1: Fix recursive fetch depth for ManyToOneRel (#117)
1 parent 8a7b641 commit 62ea6f1

File tree

7 files changed

+56
-13
lines changed

7 files changed

+56
-13
lines changed

CHANGELOG.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ Using the following categories, list your changes in this order:
2424

2525
- Nothing (yet)
2626

27+
## [2.2.1] - 2022-01-09
28+
29+
### Fixed
30+
31+
- Fixed bug where `use_query` would not recursively fetch many-to-one relationships.
32+
- IDOM preloader will now print out the exception stack when failing to import a module.
33+
2734
## [2.2.0] - 2022-12-28
2835

2936
### Added
@@ -184,7 +191,8 @@ Using the following categories, list your changes in this order:
184191

185192
- Support for IDOM within the Django
186193

187-
[unreleased]: https://github.com/idom-team/django-idom/compare/2.2.0...HEAD
194+
[unreleased]: https://github.com/idom-team/django-idom/compare/2.2.1...HEAD
195+
[2.2.1]: https://github.com/idom-team/django-idom/compare/2.2.0...2.2.1
188196
[2.2.0]: https://github.com/idom-team/django-idom/compare/2.1.0...2.2.0
189197
[2.1.0]: https://github.com/idom-team/django-idom/compare/2.0.1...2.1.0
190198
[2.0.1]: https://github.com/idom-team/django-idom/compare/2.0.0...2.0.1

src/django_idom/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from django_idom.websocket.paths import IDOM_WEBSOCKET_PATH
44

55

6-
__version__ = "2.2.0"
6+
__version__ = "2.2.1"
77
__all__ = [
88
"IDOM_WEBSOCKET_PATH",
99
"IdomWebsocket",

src/django_idom/utils.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def _register_components(self, components: set[str]) -> None:
184184
_logger.info("IDOM preloader has detected component %s", component)
185185
_register_component(component)
186186
except Exception:
187-
_logger.error(
187+
_logger.exception(
188188
"\033[91m"
189189
"IDOM failed to register component '%s'! "
190190
"This component path may not be valid, "
@@ -236,15 +236,16 @@ def django_query_postprocessor(
236236

237237
elif many_to_many and isinstance(field, ManyToManyField):
238238
prefetch_fields.append(field.name)
239+
240+
if prefetch_fields:
241+
prefetch_related_objects([data], *prefetch_fields)
242+
for field_str in prefetch_fields:
239243
django_query_postprocessor(
240-
getattr(data, field.name).get_queryset(),
244+
getattr(data, field_str).get_queryset(),
241245
many_to_many=many_to_many,
242246
many_to_one=many_to_one,
243247
)
244248

245-
if prefetch_fields:
246-
prefetch_related_objects([data], *prefetch_fields)
247-
248249
# Unrecognized type
249250
else:
250251
raise TypeError(

tests/test_app/components.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import inspect
2+
from pathlib import Path
23

34
from django.http import HttpRequest
45
from django.shortcuts import render
@@ -44,13 +45,21 @@ def parameterized_component(x, y):
4445
)
4546

4647

47-
victory = web.module_from_template("react", "victory-bar", fallback="...")
48-
VictoryBar = web.export(victory, "VictoryBar")
48+
SimpleButtonModule = web.module_from_file(
49+
"SimpleButton",
50+
Path(__file__).parent / "tests" / "js" / "simple-button.js",
51+
resolve_exports=False,
52+
fallback="...",
53+
)
54+
SimpleButton = web.export(SimpleButtonModule, "SimpleButton")
4955

5056

5157
@component
52-
def simple_bar_chart():
53-
return html._(VictoryBar(), html.hr())
58+
def simple_button():
59+
return html._(
60+
SimpleButton({"id": "simple-button"}),
61+
html.hr(),
62+
)
5463

5564

5665
@component

tests/test_app/templates/base.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ <h1>IDOM Test Page</h1>
2323
<div>{% component "test_app.components.hello_world" class="hello-world" %}</div>
2424
<div>{% component "test_app.components.button" class="button" %}</div>
2525
<div>{% component "test_app.components.parameterized_component" class="parametarized-component" x=123 y=456 %}</div>
26-
<div>{% component "test_app.components.simple_bar_chart" %}</div>
26+
<div>{% component "test_app.components.simple_button" %}</div>
2727
<div>{% component "test_app.components.use_websocket" %}</div>
2828
<div>{% component "test_app.components.use_scope" %}</div>
2929
<div>{% component "test_app.components.use_location" %}</div>
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { h, render } from "https://unpkg.com/preact?module";
2+
import htm from "https://unpkg.com/htm?module";
3+
4+
const html = htm.bind(h);
5+
6+
export function bind(node, config) {
7+
return {
8+
create: (type, props, children) => h(type, props, ...children),
9+
render: (element) => render(element, node),
10+
unmount: () => render(null, node),
11+
};
12+
}
13+
14+
export function SimpleButton(props) {
15+
return h(
16+
"button",
17+
{
18+
id: props.id,
19+
onClick(event) {
20+
props.onClick({ data: props.eventResponseData });
21+
},
22+
},
23+
"simple button"
24+
);
25+
}

tests/test_app/tests/test_components.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_parametrized_component(self):
4848
self.page.locator("#parametrized-component[data-value='579']").wait_for()
4949

5050
def test_component_from_web_module(self):
51-
self.page.wait_for_selector(".VictoryContainer")
51+
self.page.wait_for_selector("#simple-button")
5252

5353
def test_use_websocket(self):
5454
self.page.locator("#use-websocket[data-success=true]").wait_for()

0 commit comments

Comments
 (0)