bump ver, some cleanup

This commit is contained in:
collerek
2020-11-16 13:10:03 +01:00
parent d478ea6e15
commit 1168159a70
4 changed files with 20 additions and 8 deletions

View File

@ -359,8 +359,8 @@ But you can specify the `follow=True` parameter to traverse through nested model
So if you have a diamond or circular relations types you need to perform the updates in a manual way. So if you have a diamond or circular relations types you need to perform the updates in a manual way.
```python ```python
# in example like this the second Street (coming from Company) won't be save_related, so Whatever won't be updated # in example like this the second Street (coming from City) won't be save_related, so ZipCode won't be updated
Street -> District -> City -> Companies -> Street -> Whatever Street -> District -> City -> Street -> ZipCode
``` ```
## Internals ## Internals

View File

@ -30,7 +30,7 @@ class UndefinedType: # pragma no cover
Undefined = UndefinedType() Undefined = UndefinedType()
__version__ = "0.4.4" __version__ = "0.5.0"
__all__ = [ __all__ = [
"Integer", "Integer",
"BigInteger", "BigInteger",

View File

@ -234,7 +234,7 @@ class Model(NewBaseModel):
@staticmethod @staticmethod
async def _update_and_follow( async def _update_and_follow(
rel: "Model", follow: bool, visited: Set, update_count: int rel: T, follow: bool, visited: Set, update_count: int
) -> Tuple[int, Set]: ) -> Tuple[int, Set]:
if follow and rel.__class__ not in visited: if follow and rel.__class__ not in visited:
update_count = await rel.save_related( update_count = await rel.save_related(

View File

@ -161,15 +161,27 @@ async def test_saving_reversed_relation():
assert hq.companies[0].saved assert hq.companies[0].saved
assert hq.companies[1].saved assert hq.companies[1].saved
hq = await HQ.objects.select_related(
["companies", "companies__hq__nicks"]
).get(name="Main")
hq.companies[0].hq.nicks[0].name = "Sub"
assert not hq.companies[0].hq.nicks[0].saved
await hq.save_related(follow=True)
assert not hq.companies[0].hq.nicks[0].saved
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_saving_nested(): async def test_saving_nested():
async with database: async with database:
async with database.transaction(force_rollback=True): async with database.transaction(force_rollback=True):
level = await CringeLevel.objects.create(name='High') level = await CringeLevel.objects.create(name="High")
level2 = await CringeLevel.objects.create(name='Low') level2 = await CringeLevel.objects.create(name="Low")
nick1 = await NickNames.objects.create(name="BazingaO", is_lame=False, level=level) nick1 = await NickNames.objects.create(
nick2 = await NickNames.objects.create(name="Bazinga20", is_lame=True, level=level2) name="BazingaO", is_lame=False, level=level
)
nick2 = await NickNames.objects.create(
name="Bazinga20", is_lame=True, level=level2
)
hq = await HQ.objects.create(name="Main") hq = await HQ.objects.create(name="Main")
assert hq.saved assert hq.saved