Plone api and transaction issue

Good morning community,

I am using plone.api and transaction to migrate content from an Archetypes Product to a Dexterity addon in Plone. The migration manages to finish alright. The problem comes when i try to open up a NamedBlobImage file or even a NamedBlobFile. This is the error I get when trying to open up an image file to edit:

/Users/rhennebrown/Plone515/zinstance/bin/python /Users/rhennebrown/Plone515/zinstance/bin/instance fg
2021-01-26 10:34:46 INFO ZServer HTTP server started at Tue Jan 26 10:34:46 2021
Hostname: 0.0.0.0
Port: 8080
2021-01-26 10:34:49 INFO DocFinderTab Applied patch version 1.0.5.
/Users/rhennebrown/Plone515/zinstance/products/FacultyCV/init.py:45: DeprecationWarning: package_home is deprecated. import from App.Common instead
from Globals import package_home
/Users/rhennebrown/Plone515/buildout-cache/eggs/plone.app.blob-1.7.4-py2.7.egg/plone/app/blob/content.py:23: DeprecationWarning: MimeTypeException is deprecated. Import from Products.MimetypesRegistry.interfaces instead
from Products.MimetypesRegistry.common import MimeTypeException
/Users/rhennebrown/Plone515/buildout-cache/eggs/plone.portlet.collection-3.3.1-py2.7.egg/plone/portlet/collection/collection.py:2: DeprecationWarning: isDefaultPage is deprecated. Import from Products.CMFPlone instead
from plone.app.layout.navigation.defaultpage import isDefaultPage
/Users/rhennebrown/Plone515/buildout-cache/eggs/Products.CMFPlone-5.1.5-py2.7.egg/Products/CMFPlone/browser/syndication/views.py:17: DeprecationWarning: wrap_form is deprecated. Import from plone.z3cform.layout instead.
from plone.app.z3cform.layout import wrap_form
2021-01-26 10:34:55 WARNING plone.behavior Specifying 'for' in behavior 'Tiles' if no 'factory' is given has no effect and is superfluous.
/Users/rhennebrown/Plone515/buildout-cache/eggs/Zope2-2.13.27-py2.7.egg/OFS/Application.py:102: DeprecationWarning: Expected text
transaction.get().note("Created Zope Application")
/Users/rhennebrown/Plone515/buildout-cache/eggs/Zope2-2.13.27-py2.7.egg/OFS/Application.py:267: DeprecationWarning: Expected text
transaction.get().note(note)
/Users/rhennebrown/Plone515/buildout-cache/eggs/Zope2-2.13.27-py2.7.egg/OFS/Application.py:523: DeprecationWarning: Expected text
transaction.get().note('Prior to product installs')
2021-01-26 10:34:58 INFO Zope Ready to handle requests
/Users/rhennebrown/Plone515/buildout-cache/eggs/Products.CMFCore-2.2.12-py2.7.egg/Products/CMFCore/DirectoryView.py:493: UserWarning: DirectoryView facultycv_styles refers to a non-existing path 'FacultyCV/skins/facultycv_styles'
(self.id, reg_key), UserWarning)
Starting Migration
Creating directory
/Users/rhennebrown/Plone515/buildout-cache/eggs/Zope2-2.13.27-py2.7.egg/Zope2/App/startup.py:344: DeprecationWarning: Expected text
T.note(path)
/Users/rhennebrown/Plone515/buildout-cache/eggs/Zope2-2.13.27-py2.7.egg/Zope2/App/startup.py:357: DeprecationWarning: Expected text
T.setUser(auth_user.getId(), auth_path)
2021-01-26 10:38:49 INFO ExtendedPathIndex Attempt to unindex nonexistent object with id -1716284823
Directory created
/Plone/directory
Brown, Rhenne

2021-01-26 10:38:49 INFO ExtendedPathIndex Attempt to unindex nonexistent object with id -1716284821
Staff created
Brown, Rhenne
2021-01-26 10:38:49 INFO ExtendedPathIndex Attempt to unindex nonexistent object with id -1716284819
Faculty created
First reappointment
pbAction created
Second Reappointment
2021-01-26 10:38:49 INFO ExtendedPathIndex Attempt to unindex nonexistent object with id -1716284815
pbActionCLT created
Third Reappointment
2021-01-26 10:38:50 INFO ExtendedPathIndex Attempt to unindex nonexistent object with id -1716284813
pbActionLeave created
Third Reappointment
2021-01-26 10:38:50 INFO ExtendedPathIndex Attempt to unindex nonexistent object with id -1716284811
pbActionPortfolio0 created
Fourth Reappointment
2021-01-26 10:38:50 INFO ExtendedPathIndex Attempt to unindex nonexistent object with id -1716284809
pbActionPortfolio0 created
Fifth Reappointment
2021-01-26 10:38:51 INFO ExtendedPathIndex Attempt to unindex nonexistent object with id -1716284807
pbActionPortfolio1 created
Sixth Reappointment
2021-01-26 10:38:51 INFO ExtendedPathIndex Attempt to unindex nonexistent object with id -1716284805
pbActionPortfolio2 created
Seventh Reappointment
2021-01-26 10:38:51 INFO ExtendedPathIndex Attempt to unindex nonexistent object with id -1716284803
pbActionScholar created
/Users/rhennebrown/Plone515/buildout-cache/eggs/zope.deprecation-4.3.0-py2.7.egg/zope/deprecation/deprecation.py:88: DeprecationWarning: isDefaultPage is deprecated. Import from Products.CMFPlone.defaultpage instead
name)
/Users/rhennebrown/Plone515/buildout-cache/eggs/Chameleon-2.25-py2.7.egg/chameleon/tal.py:471: DeprecationWarning: Using len() is deprecated. Use the length attribute for the size of the current page, which is what we return now. Use the sequence_length attribute for the size of the entire sequence.
iterable = list(iterable) if iterable is not None else ()
2021-01-26 10:38:56 ERROR plone.namedfile.scaling Could not scale "<Image at /Plone/portal_college/brown-rhenne/image used for /Plone/directory/brown-rhenne>" of <bound method Staff.absolute_url of <Staff at /Plone/directory/brown-rhenne>>
Traceback (most recent call last):
File "/Users/rhennebrown/Plone515/buildout-cache/eggs/plone.namedfile-4.2.6-py2.7.egg/plone/namedfile/scaling.py", line 253, in call
**parameters
File "/Users/rhennebrown/Plone515/buildout-cache/eggs/plone.namedfile-4.2.6-py2.7.egg/plone/namedfile/scaling.py", line 200, in create_scale
**parameters
File "/Users/rhennebrown/Plone515/buildout-cache/eggs/plone.scale-3.0.3-py2.7.egg/plone/scale/scale.py", line 55, in scaleImage
image = PIL.Image.open(image)
File "/Users/rhennebrown/Plone515/buildout-cache/eggs/Pillow-5.4.1-py2.7-macosx-10.9-x86_64.egg/PIL/Image.py", line 2640, in open
fp = io.BytesIO(fp.read())
AttributeError: 'Image' object has no attribute 'read'
2021-01-26 10:38:57 ERROR plone.namedfile.scaling Could not scale "<Image at /Plone/portal_college/brown-rhenne-1/image used for /Plone/directory/brown-rhenne-1>" of <bound method Faculty.absolute_url of <Faculty at /Plone/directory/brown-rhenne-1>>
Traceback (most recent call last):
File "/Users/rhennebrown/Plone515/buildout-cache/eggs/plone.namedfile-4.2.6-py2.7.egg/plone/namedfile/scaling.py", line 253, in call
**parameters
File "/Users/rhennebrown/Plone515/buildout-cache/eggs/plone.namedfile-4.2.6-py2.7.egg/plone/namedfile/scaling.py", line 200, in create_scale
**parameters
File "/Users/rhennebrown/Plone515/buildout-cache/eggs/plone.scale-3.0.3-py2.7.egg/plone/scale/scale.py", line 55, in scaleImage
image = PIL.Image.open(image)
File "/Users/rhennebrown/Plone515/buildout-cache/eggs/Pillow-5.4.1-py2.7-macosx-10.9-x86_64.egg/PIL/Image.py", line 2640, in open
fp = io.BytesIO(fp.read())
AttributeError: 'Image' object has no attribute 'read'

Apparently, the plone.scale version you are using expects an Image object to have a read method. Obviously, this is not the case for your Image object. Check which versions of plone.scale are available - maybe, you need a newer or older one.

Thank you for responding.

I tried both a newer version of the plone.scale and an older version of the plone.scale. Unfortunately, this is the error that came up:

/Users/rhennebrown/Plone515/zinstance/bin/python /Users/rhennebrown/Plone515/zinstance/bin/instance fg
2021-01-26 14:27:07 INFO ZServer HTTP server started at Tue Jan 26 14:27:07 2021
	Hostname: 0.0.0.0
	Port: 8080
2021-01-26 14:27:11 INFO DocFinderTab Applied patch version 1.0.5.
/Users/rhennebrown/Plone515/zinstance/products/FacultyCV/__init__.py:45: DeprecationWarning: package_home is deprecated. import from App.Common instead
  from Globals import package_home
/Users/rhennebrown/Plone515/buildout-cache/eggs/plone.app.blob-1.7.4-py2.7.egg/plone/app/blob/content.py:23: DeprecationWarning: MimeTypeException is deprecated. Import from Products.MimetypesRegistry.interfaces instead
  from Products.MimetypesRegistry.common import MimeTypeException
/Users/rhennebrown/Plone515/buildout-cache/eggs/plone.portlet.collection-3.3.1-py2.7.egg/plone/portlet/collection/collection.py:2: DeprecationWarning: isDefaultPage is deprecated. Import from Products.CMFPlone instead
  from plone.app.layout.navigation.defaultpage import isDefaultPage
/Users/rhennebrown/Plone515/buildout-cache/eggs/Products.CMFPlone-5.1.5-py2.7.egg/Products/CMFPlone/browser/syndication/views.py:17: DeprecationWarning: wrap_form is deprecated. Import from plone.z3cform.layout instead.
  from plone.app.z3cform.layout import wrap_form
2021-01-26 14:27:17 WARNING plone.behavior Specifying 'for' in behavior 'Tiles' if no 'factory' is given has no effect and is superfluous.
/Users/rhennebrown/Plone515/buildout-cache/eggs/Zope2-2.13.27-py2.7.egg/OFS/Application.py:102: DeprecationWarning: Expected text
  transaction.get().note("Created Zope Application")
/Users/rhennebrown/Plone515/buildout-cache/eggs/Zope2-2.13.27-py2.7.egg/OFS/Application.py:267: DeprecationWarning: Expected text
  transaction.get().note(note)
/Users/rhennebrown/Plone515/buildout-cache/eggs/Zope2-2.13.27-py2.7.egg/OFS/Application.py:523: DeprecationWarning: Expected text
  transaction.get().note('Prior to product installs')
2021-01-26 14:27:20 INFO Zope Ready to handle requests
/Users/rhennebrown/Plone515/buildout-cache/eggs/Products.CMFCore-2.2.12-py2.7.egg/Products/CMFCore/DirectoryView.py:493: UserWarning: DirectoryView facultycv_styles refers to a non-existing path 'FacultyCV/skins/facultycv_styles'
  (self.id, reg_key), UserWarning)
/Users/rhennebrown/Plone515/buildout-cache/eggs/Zope2-2.13.27-py2.7.egg/Zope2/App/startup.py:344: DeprecationWarning: Expected text
  T.note(path)
/Users/rhennebrown/Plone515/buildout-cache/eggs/Zope2-2.13.27-py2.7.egg/Zope2/App/startup.py:357: DeprecationWarning: Expected text
  T.setUser(auth_user.getId(), auth_path)
Starting Migration
Creating directory
2021-01-26 14:27:24 INFO ExtendedPathIndex Attempt to unindex nonexistent object with id -726968436
Directory created
/Plone/directory
Brown, Rhenne
<College at directory>
2021-01-26 14:27:25 INFO ExtendedPathIndex Attempt to unindex nonexistent object with id -726968434
Staff created
Brown, Rhenne
2021-01-26 14:27:25 INFO ExtendedPathIndex Attempt to unindex nonexistent object with id -726968432
Faculty created
First reappointment
pbAction created
Second Reappointment
2021-01-26 14:27:25 INFO ExtendedPathIndex Attempt to unindex nonexistent object with id -726968428
pbActionCLT created
Third Reappointment
2021-01-26 14:27:26 INFO ExtendedPathIndex Attempt to unindex nonexistent object with id -726968426
pbActionLeave created
Third Reappointment
2021-01-26 14:27:26 INFO ExtendedPathIndex Attempt to unindex nonexistent object with id -726968424
pbActionPortfolio0 created
Fourth Reappointment
2021-01-26 14:27:26 INFO ExtendedPathIndex Attempt to unindex nonexistent object with id -726968422
pbActionPortfolio0 created
Fifth Reappointment
2021-01-26 14:27:26 INFO ExtendedPathIndex Attempt to unindex nonexistent object with id -726968420
pbActionPortfolio1 created
Sixth Reappointment
2021-01-26 14:27:27 INFO ExtendedPathIndex Attempt to unindex nonexistent object with id -726968418
pbActionPortfolio2 created
Seventh Reappointment
2021-01-26 14:27:27 INFO ExtendedPathIndex Attempt to unindex nonexistent object with id -726968416
pbActionScholar created
/Users/rhennebrown/Plone515/buildout-cache/eggs/zope.deprecation-4.3.0-py2.7.egg/zope/deprecation/deprecation.py:88: DeprecationWarning: isDefaultPage is deprecated. Import from Products.CMFPlone.defaultpage instead
  name)
/Users/rhennebrown/Plone515/buildout-cache/eggs/Chameleon-2.25-py2.7.egg/chameleon/tal.py:471: DeprecationWarning: Using len() is deprecated. Use the `length` attribute for the size of the current page, which is what we return now. Use the `sequence_length` attribute for the size of the entire sequence. 
  iterable = list(iterable) if iterable is not None else ()
2021-01-26 14:27:31 ERROR plone.namedfile.scaling Could not scale "<Image at /Plone/portal_college/brown-rhenne/image used for /Plone/directory/brown-rhenne>" of <bound method Staff.absolute_url of <Staff at /Plone/directory/brown-rhenne>>
Traceback (most recent call last):
  File "/Users/rhennebrown/Plone515/buildout-cache/eggs/plone.namedfile-4.2.6-py2.7.egg/plone/namedfile/scaling.py", line 253, in __call__
    **parameters
  File "/Users/rhennebrown/Plone515/buildout-cache/eggs/plone.namedfile-4.2.6-py2.7.egg/plone/namedfile/scaling.py", line 200, in create_scale
    **parameters
  File "/Users/rhennebrown/Plone515/buildout-cache/eggs/plone.scale-3.1.2-py2.7.egg/plone/scale/scale.py", line 57, in scaleImage
    image = PIL.Image.open(image)
  File "/Users/rhennebrown/Plone515/buildout-cache/eggs/Pillow-5.4.1-py2.7-macosx-10.9-x86_64.egg/PIL/Image.py", line 2640, in open
    fp = io.BytesIO(fp.read())
AttributeError: 'Image' object has no attribute 'read'
2021-01-26 14:27:31 ERROR plone.namedfile.scaling Could not scale "<Image at /Plone/portal_college/brown-rhenne-1/image used for /Plone/directory/brown-rhenne-1>" of <bound method Faculty.absolute_url of <Faculty at /Plone/directory/brown-rhenne-1>>
Traceback (most recent call last):
  File "/Users/rhennebrown/Plone515/buildout-cache/eggs/plone.namedfile-4.2.6-py2.7.egg/plone/namedfile/scaling.py", line 253, in __call__
    **parameters
  File "/Users/rhennebrown/Plone515/buildout-cache/eggs/plone.namedfile-4.2.6-py2.7.egg/plone/namedfile/scaling.py", line 200, in create_scale
    **parameters
  File "/Users/rhennebrown/Plone515/buildout-cache/eggs/plone.scale-3.1.2-py2.7.egg/plone/scale/scale.py", line 57, in scaleImage
    image = PIL.Image.open(image)
  File "/Users/rhennebrown/Plone515/buildout-cache/eggs/Pillow-5.4.1-py2.7-macosx-10.9-x86_64.egg/PIL/Image.py", line 2640, in open
    fp = io.BytesIO(fp.read())
AttributeError: 'Image' object has no attribute 'read'

What else do I need to try?
I thank you kindly.

rbrown12

What Plone version are you using?

Does the error occur before or after you have migrated the image, i.e. is the image still an Archetype or already a dexterity object? Maybe, plone.scaling is broken for dexterity objects? I usually read the change log (often included on the PyPI page) to find out whether a specific version is supposed to work with some other component (in this case Archetypes versus dexterity).

I am currently using Plone 5.1.5 for this project. The error occurs after I have migrated the image. The image i am migrating was from an Archetypes content type. I am migrating the image to a Dexterity content type.

I have verified that plone.app.contenttypes.content.Image objects do not have a read method. The problem you are observing is an incompatibility between your version of plone.scaling and dexterity.

My Plone 5.2 test instance no longer has plone.scaling installed. Thus, this may be a known problem.

Did you get Archetypes to work on Plone 5.2? If so, what did you need to do?

The problem for Archetypes is Python 3, not Plone 5.2.

(Python 2 +) Plone 5.2 seemed to work well with Archetypes -- though I moved quickly to dexterity.

Thank you for your help. I was able to fix the problem by using

NamedBlobImage(data=object.image.data, filename=unicode(object.image.filename))

and

NamedBlobFile(data=object.toPresident.data, filename=unicode(object.toPresident.filename)).