Skip to content

Incorrect use of getattr causes unnecessary log entries #192

@marwoe

Description

@marwoe

Using getattr without a default value raises an AttributeError, which means the else block is never executed.

On a classic Plone site this leads to unnecessary log entries when uploading a JPG as site logo via the control panel. In that scenario the logo is stored in the registry as raw bytes and therefore has no name attribute.

Although using a different file type (non-JPG) might avoid the issue temporarily, the underlying code is fundamentally incorrect and should be fixed.

Affected Code
https://github.com/plone/plone.namedfile/blob/8286972b4452234c2342534e6fb6ebf549a3d64c/src/plone/namedfile/utils/init.py#L271

Steps to reproduce

  1. Use a Classic Plone site (6.1.2 or above).
  2. Open the control panel.
  3. Upload a JPG file as site logo.
  4. Visit the homepage or any other page within the Plone site.

Actual behavior

AttributeError is raised and unnecessary log entries get written.

Expected behavior

The code should handle missing attributes gracefully by supplying a default value to getattr, thus avoiding the exception.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions