Closed johncarter-phntm closed 1 year ago
fwiw, my workaround for this was https://github.com/torchbox/wagtail-grapple/pull/270/commits/b3e6883d5e9154b137f803ce2a58c60e4ebbc9d9#diff-0fda90953a8234a646f51996c7a14f3d7976713a8a27f3815701cf98c299c883R46, but I did not have the chance to dive deeper
Same error while upgrading from Wagtail 4.0.4 to 4.1 ! Obviously, wagtail_factories.ListBlockFactory is now buggy... (list instead of bound_blocks as expected)
@zerolab thanks for the workaround ! In my custom wagtail_factories.StructBlockFactory factory, I'm now defining attribute with ListValue(ListBlock(MyCustomBlock()), values=[{.. fields...}])
instead of ListBlockFactory...
This isn't dynamic (factory boy way) but at least, we could jump to wagtail 4.1...
Hope a real fix could be done quickly!
For instance, here is the models :
class SkillLinkBlock(blocks.StructBlock):
title = blocks.CharBlock(max_length=128)
page = blocks.PageChooserBlock(label='Page', required=False)
class Meta:
icon = 'link'
value_class = SkillLinkStructValue
class SkillBlock(blocks.StructBlock):
heading = blocks.CharBlock(max_length=128)
links = blocks.ListBlock(SkillLinkBlock(), collapsed=True)
class Meta:
template = 'portfolio/blocks/skill_grid.html'
icon = 'code'
class SkillsBlock(blocks.StreamBlock):
skill = SkillBlock()
class Meta:
template = 'portfolio/blocks/skills.html'
icon = 'code'
and the factories:
class SkillLinkBlockFactory(wagtail_factories.StructBlockFactory):
class Meta:
model = SkillLinkBlock
title = factory.Faker('sentence', nb_words=3, locale=current_locale)
page = factory.SubFactory(wagtail_factories.PageChooserBlockFactory)
class SkillBlockFactory(wagtail_factories.StructBlockFactory):
class Meta:
model = SkillBlock
heading = factory.Faker('sentence', nb_words=3, locale=current_locale)
# BROKEN ListBlockFactory... worked with Wagtail 4.0.4
# links = wagtail_factories.ListBlockFactory(SkillLinkBlockFactory)
# Unfortunetly, cannot use SkillLinkBlockFactory...
links = ListValue(ListBlock(SkillLinkBlock()), values=[
{
'title': fake.sentence(nb_words=3),
'page': wagtail_factories.PageChooserBlockFactory(),
},
])
class SkillsBlockFactory(wagtail_factories.StreamBlockFactory):
class Meta:
model = SkillsBlock
skill = factory.SubFactory(SkillBlockFactory)
But afterall, maybe I was a lucky guy and didn't use well ListBlock... ?
I've added a WIP fix in #66 , not sure if this is the right approach or not though.
FWIW, as a quick fix I implemented a subclassed version of the solution @johncarter-phntm proposes (thanks) for generating development data. I'm not thrilled about introducing the tech debt.
from wagtail.blocks import list_block
class CustomListBlockFactory(wagtail_factories.ListBlockFactory):
def evaluate(self, instance, step, extra):
retval = super().evaluate(instance, step, extra)
block_model = self.get_factory()._meta.model
return list_block.ListValue(list_block.ListBlock(block_model), values=retval)
I'm hitting a similar error with my own factories, it looks like passing a list into a ListBlock is the problem.
Example error: