Skip to content

v2.2.1: Fix recursive fetch depth for ManyToOneRel #117

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 9 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ Using the following categories, list your changes in this order:

- Nothing (yet)

## [2.2.1] - 2022-01-02

### Fixed

- Fixed bug where `use_query` would not recursively fetch many-to-one relationships.

## [2.2.0] - 2022-12-28

### Added
Expand Down Expand Up @@ -184,7 +190,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
Expand Down
2 changes: 1 addition & 1 deletion src/django_idom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 5 additions & 4 deletions src/django_idom/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
13 changes: 9 additions & 4 deletions tests/test_app/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,18 @@ def parameterized_component(x, y):
)


victory = web.module_from_template("react", "victory-bar", fallback="...")
VictoryBar = web.export(victory, "VictoryBar")
SimpleButtonModule = web.module_from_url(
"/static/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
Expand Down
25 changes: 25 additions & 0 deletions tests/test_app/static/simple-button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { h, render } from "https://unpkg.com/preact?module";
import htm from "https://unpkg.com/htm?module";

const html = htm.bind(h);

export function bind(node, config) {
return {
create: (type, props, children) => h(type, props, ...children),
render: (element) => render(element, node),
unmount: () => render(null, node),
};
}

export function SimpleButton(props) {
return h(
"button",
{
id: props.id,
onClick(event) {
props.onClick({ data: props.eventResponseData });
},
},
"simple button"
);
}
2 changes: 1 addition & 1 deletion tests/test_app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h1>IDOM Test Page</h1>
<div>{% component "test_app.components.hello_world" class="hello-world" %}</div>
<div>{% component "test_app.components.button" class="button" %}</div>
<div>{% component "test_app.components.parameterized_component" class="parametarized-component" x=123 y=456 %}</div>
<div>{% component "test_app.components.simple_bar_chart" %}</div>
<div>{% component "test_app.components.simple_button" %}</div>
<div>{% component "test_app.components.use_websocket" %}</div>
<div>{% component "test_app.components.use_scope" %}</div>
<div>{% component "test_app.components.use_location" %}</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/test_app/tests/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_parametrized_component(self):
self.page.locator("#parametrized-component[data-value='579']").wait_for()

def test_component_from_web_module(self):
self.page.wait_for_selector(".VictoryContainer")
self.page.wait_for_selector("#simple-button")

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