ImagePreviewCollection.load and ImagePreviewCollection.new don't behave as described in the Python API docs #63651

Closed
opened 2019-04-16 10:07:04 +02:00 by Jasper van Nieuwenhuizen · 8 comments

System Information
Operating system: Linux-5.0.7-200.fc29.x86_64-x86_64-with-fedora-29-Twenty_Nine 64 Bits
Graphics card: GeForce GTX 980 Ti/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 390.116

Blender Version
Broken: version: 2.80 (sub 57), branch: blender2.7, commit date: 2019-04-15 23:42, hash: 5ac7675f4c (from the buildbot) - also 2.79.6
Worked: I suspect it never worked as documented.

Short description of error
The Python API docs state for ImagePreviewCollection.load and for ImagePreviewCollection.new that is should return "The Preview matching given name, or a new empty one.". In reality it raises an exception when the Preview already exists.

Exact steps for others to reproduce the error
Go to the Python console and type the following.

pcoll = bpy.utils.previews.new()
pcoll.new('test')
pcoll.new('test')  # Error
pcoll.load('test', '', 'IMAGE')  # Error

In the python code a check is done that raises an exception if the Preview already exists (for load there is even a little typo, it should be a format string: f"key {name!r} already exists").
As far as I can see the underlying C code manages existing Previews just fine and has the behavior described in the docs. So I would propose to remove the check from the Python code. Another option would be to properly return the existing Preview from the Python code.
Of course another option would be to change the docs, but personally I would prefer to have the documented behavior.

I've attached 2 patches. 1 for removing the check in the Python code and 1 with the corrected check. The patches should apply to both 2.79 and 2.80.

ImagePreviewCollection_load_new-check_removed.diff
ImagePreviewCollection_load_new-check_fixed.diff

**System Information** Operating system: Linux-5.0.7-200.fc29.x86_64-x86_64-with-fedora-29-Twenty_Nine 64 Bits Graphics card: GeForce GTX 980 Ti/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 390.116 **Blender Version** Broken: version: 2.80 (sub 57), branch: blender2.7, commit date: 2019-04-15 23:42, hash: `5ac7675f4c` (from the buildbot) - also 2.79.6 Worked: I suspect it never worked as documented. **Short description of error** The Python API docs state for `ImagePreviewCollection.load` and for `ImagePreviewCollection.new` that is should return "The Preview matching given name, or a new empty one.". In reality it raises an exception when the Preview already exists. **Exact steps for others to reproduce the error** Go to the Python console and type the following. ``` pcoll = bpy.utils.previews.new() pcoll.new('test') pcoll.new('test') # Error pcoll.load('test', '', 'IMAGE') # Error ``` In the python code a check is done that raises an exception if the Preview already exists (for `load` there is even a little typo, it should be a format string: `f"key {name!r} already exists"`). As far as I can see the underlying C code manages existing Previews just fine and has the behavior described in the docs. So I would propose to remove the check from the Python code. Another option would be to properly return the existing Preview from the Python code. Of course another option would be to change the docs, but personally I would prefer to have the documented behavior. I've attached 2 patches. 1 for removing the check in the Python code and 1 with the corrected check. The patches should apply to both 2.79 and 2.80. [ImagePreviewCollection_load_new-check_removed.diff](https://archive.blender.org/developer/F6950795/ImagePreviewCollection_load_new-check_removed.diff) [ImagePreviewCollection_load_new-check_fixed.diff](https://archive.blender.org/developer/F6950796/ImagePreviewCollection_load_new-check_fixed.diff)

Added subscriber: @jasperge-2

Added subscriber: @jasperge-2
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Philipp Oeser self-assigned this 2019-04-16 10:18:34 +02:00
Member

Sounds reasonable, will check with others though [and commit if agreed upon]

thx for the patch

Sounds reasonable, will check with others though [and commit if agreed upon] thx for the patch

Before the final release I think this should be fixed. I noticed this bug is still in the release candidate.

Before the final release I think this should be fixed. I noticed this bug is still in the release candidate.

@lichtwerk Any updates on this? Would be nice to get it in for the release.

@lichtwerk Any updates on this? Would be nice to get it in for the release.
Philipp Oeser removed their assignment 2019-07-24 08:48:34 +02:00
Member

I am not available to look into this this week, so it might not make it into 2.80, but can step down from it, so others can pick it up.
Sorry this has been lying around, other things had higher priority...

I am not available to look into this this week, so it might not make it into 2.80, but can step down from it, so others can pick it up. Sorry this has been lying around, other things had higher priority...

This issue was referenced by 971fe43d06

This issue was referenced by 971fe43d06ddad94933666c89c40ed345338992a

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Campbell Barton self-assigned this 2020-09-17 04:51:16 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#63651
No description provided.