Skip to content

better error handling while srcset creation is needed #202

@1letter

Description

@1letter

in a template i define two tags:

<metal:row define-macro="teaser"
             tal:define="
               plone_view python:context.restrictedTraverse('@@plone');
               obj item/getObject;
               scale nocall:obj/@@images;
               tag python:scale.tag('image', width=800, height=350, mode='contain', loading='lazy');
               tag1 python: scale.srcset('image', width=1600, height=700, mode='contain', css_class='cover', loading='lazy', fetchpriority='high', alt=getattr(context, 'image_caption', None));
             "
  >

the srcset creation is broken if the imagefield is empty, the tag creation works without errors (it return None)

File "/opt/ukdd-p6.1/.venv/lib/python3.12/site-packages/plone/namedfile/scaling.py", line 803, in srcset
    attributes["src"] = scale.url
                        ^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'url'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions