django-fastdev icon indicating copy to clipboard operation
django-fastdev copied to clipboard

Invalid blocks check is faulty

Open Mte90 opened this issue 1 year ago • 8 comments

With https://github.com/unfoldadmin/django-unfold in my case is Invalid blocks specified: for branding. Also if I put django_fastdev as last app I am getting that error for a block of that template of that package that I don't duplicated in my project.

After investigating a bit in my case is that the blocks doesn't exist as it is a package that has a logic to not print them if found them in various HTML files so the logic right now doens't work.

For fastdev is invalid but in reality is not declared or unused. It should load all the template files to check if a block exists or not and the alert should be different but right now there are no options to disable that alert.

As you can see on https://github.com/unfoldadmin/django-unfold/blob/541a1577ec93630a9c99ec623d395a26c7098b65/src/unfold/templates/unfold/helpers/navigation.html#L10 if the block is not available the file is not loaded so the block for fastdev is not valid but in reality there shouldn't be any errors.

Mte90 avatar Nov 06 '24 11:11 Mte90

Hmm, I don't understand. You are talking about the invalid block check, but you link to code that references a variable, not a block. I don't see the connection.

boxed avatar Nov 06 '24 12:11 boxed

So the capture custom block for branding: https://github.com/unfoldadmin/django-unfold/blob/541a1577ec93630a9c99ec623d395a26c7098b65/src/unfold/templates/unfold/layouts/skeleton.html#L6 A capturenode in unfold: https://github.com/unfoldadmin/django-unfold/blob/541a1577ec93630a9c99ec623d395a26c7098b65/src/unfold/templatetags/unfold.py#L79

With the actual code in fastdev is not detect and reported as invalid block.

Mte90 avatar Nov 06 '24 14:11 Mte90

Ah. I see the problem. CaptureNode is incorrect. It does not declare child_nodelists = ('nodelist',) as it should.

boxed avatar Nov 06 '24 14:11 boxed

Reported at https://github.com/unfoldadmin/django-unfold/issues/839

Mte90 avatar Nov 06 '24 14:11 Mte90

You can also easily monkey patch that attribute yourself to verify.

boxed avatar Nov 06 '24 14:11 boxed

Suggestions on how to do that?

Mte90 avatar Nov 06 '24 14:11 Mte90

Write

CaptureNode.child_nodelists = ('nodelist', )

somewhere where it is run before the template is loaded.

boxed avatar Nov 06 '24 14:11 boxed

I opened a PR with the patch on https://github.com/unfoldadmin/django-unfold/pull/863#issuecomment-2485401712 but does't seems that fix the issue

Mte90 avatar Nov 19 '24 11:11 Mte90