Page MenuHome

`ImagePreviewCollection.load` and `` don't behave as described in the Python API docs
Open, NormalPublic


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: rB5ac7675f4c9c (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 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 ='test')'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.



Event Timeline

Philipp Oeser (lichtwerk) claimed this task.
Philipp Oeser (lichtwerk) triaged this task as Normal priority.

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.

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

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...