Skip to content

Commit 3ebef73

Browse files
fix linting
1 parent f2cfdb6 commit 3ebef73

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

src/django_unicorn/views/utils.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from dataclasses import is_dataclass
33
from typing import Any, Union, cast, get_args, get_origin
44

5-
from django.db.models import Model
5+
from django.db.models import Field, Model
66

77
from django_unicorn.components import UnicornField, UnicornView
88
from django_unicorn.decorators import timed
@@ -53,11 +53,16 @@ def set_property_from_data(
5353
if model_field.is_relation and model_field.many_to_one:
5454
if isinstance(value, Model):
5555
setattr(component_or_field, name, value)
56-
else:
56+
elif isinstance(model_field, Field):
5757
setattr(component_or_field, model_field.attname, value)
5858
return
59-
except Exception:
60-
pass
59+
except Exception as exc:
60+
logger.debug(
61+
"Unable to assign '%s' on component '%s'",
62+
model_field.attname,
63+
type(component_or_field).__name__,
64+
exc_info=exc,
65+
)
6166

6267
# UnicornField and Models are always a dictionary (can be nested)
6368
if component_field_is_model_or_unicorn_field:

tests/views/test_fk_loading.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
21
import pytest
2+
from tests.views.message.utils import post_and_get_response
3+
34
from django_unicorn.components import UnicornView
45
from example.coffee.models import Flavor
5-
from tests.views.message.utils import post_and_get_response
6+
67

78
class TestIssue732View(UnicornView):
89
template_name = "templates/test_component.html"
9-
flavor: Flavor = None
10+
flavor: Flavor | None = None
1011

1112
def mount(self):
1213
pass
@@ -17,6 +18,7 @@ def load_flavor(self, flavor_id):
1718
def save(self):
1819
self.flavor.save()
1920

21+
2022
@pytest.mark.django_db
2123
def test_fk_loading(client):
2224
# Setup
@@ -35,22 +37,22 @@ def test_fk_loading(client):
3537
url="/message/tests.views.test_fk_loading.TestIssue732View",
3638
action_queue=action_queue,
3739
)
38-
40+
3941
assert not response.get("error")
4042
data = response["data"]
41-
43+
4244
# Verify flavor is in data
4345
assert "flavor" in data
4446
assert data["flavor"]["pk"] == child_flavor.pk
45-
47+
4648
# 2. Execute 'save' with the returned data
4749
action_queue = [
4850
{
4951
"payload": {"name": "save", "args": []},
5052
"type": "callMethod",
5153
}
5254
]
53-
55+
5456
# This is where it should fail without the fix
5557
response = post_and_get_response(
5658
client,
@@ -59,7 +61,4 @@ def test_fk_loading(client):
5961
action_queue=action_queue,
6062
)
6163

62-
if "error" in response:
63-
print(f"Error: {response['error']}")
64-
6564
assert not response.get("error")

0 commit comments

Comments
 (0)