wagtail / wagtail-factories

Factory boy classes for wagtail
http://wagtail-factories.readthedocs.io/en/latest/
MIT License
102 stars 41 forks source link

ListBlockFactory breaks when passing deeply nested arguments to list items #52

Closed bcdickinson closed 2 years ago

bcdickinson commented 2 years ago

Trying to use deeply nested arguments to ListBlock items via ListBlockFactory results in the following error:

...
  File "/venv/lib/python3.8/site-packages/wagtail_factories/blocks.py", line 81, in generate
    prefix, label = key.split("__", 2)
ValueError: too many values to unpack (expected 2)

This happens if your list block item factories themselves contain SubFactory declarations:

class ListItemFactory(wagtail_factories.StructBlockFactory):
  class Meta:
    model = ListItem

  some_fk = factory.SubFactory(MyOtherModelFactory)

Then this sort of thing fails:

MyPageFactory(body__0__list__0__some_fk__some_attribute="foo")

I'm pretty sure that the 2 passed to str.split here should be a 1: https://github.com/wagtail/wagtail-factories/blob/d4fcf1d84f2ee5feaa63d974df44ae7b0626ee27/src/wagtail_factories/blocks.py#L82

jams2 commented 2 years ago

Fixed in #55