Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage.py _cleanup TypeError: unsupported operand type(s) for -: 'str' and 'int' #12

Closed
1letter opened this issue Aug 27, 2016 · 5 comments

Comments

@1letter
Copy link

1letter commented Aug 27, 2016

Hi, i get an error while rendering an template with Images. I use Plone 4.3.9. Please no irritations because of the path in the traceback.

  File "/opt/Plone-4.3.3/buildout-cache/eggs/plone.scale-1.4.1-py2.7.egg/plone/scale/storage.py", line 166, in scale
    self._cleanup()
  File "/opt/Plone-4.3.3/buildout-cache/eggs/plone.scale-1.4.1-py2.7.egg/plone/scale/storage.py", line 190, in _cleanup
    value['modified'] < modified_time - KEEP_SCALE_MILLIS):
TypeError: unsupported operand type(s) for -: 'str' and 'int'

# Here my Debug Output of the Values:
2016-08-27 18:58:05 INFO plone.scale key: d7620496-5e61-4f6b-8490-b30399d809ba
2016-08-27 18:58:05 INFO plone.scale modified time     1467291549.8024411467291549.8028791467291549.8032841467291549.8036901467291549.804092
2016-08-27 18:58:05 INFO plone.scale value['modified'] 1467291549.8024411467291549.8028791467291549.8032841467291549.8036901467291549.804092

I think it's not an Integer, all values are 'str'. The comparison but needs integer values . What should i do? Should I overwrite the _cleanup Method and purge the Storage every time?

@mauritsvanrees
Copy link
Member

Both 'modified' values should be integers or floats. It is the same as what you get when you run context.modified() or the same type as when running time.time().

Is this with the standard Image content type of Plone? Or a different one from own code or an add-on? Maybe you have code that overrides the modified method to do something weird.

The two values you pasted above are the same. What is strange, is that they start with 1467291549.802441 followed by the same value a couple of times, except for the part after the dot.

You could check isinstance(modified_time, (float, int)). If that is False, then there is no sense in subtracting a value. Same for value['modified']. I guess in that case it is best to simply compare the two values and delete the scale if they are different.

mister-roboto pushed a commit to plone/buildout.coredev that referenced this issue Oct 23, 2016
Branch: refs/heads/1.4.x
Date: 2016-10-22T22:53:44-04:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.scale@05d238a

Avoid TypeErrors when looking for outdated scales.

Fixes plone/plone.scale#12

Files changed:
M CHANGES.rst
M plone/scale/storage.py
Repository: plone.scale
Branch: refs/heads/1.4.x
Date: 2016-10-22T22:53:44-04:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.scale@9d95279

When getting an outdated scale, don't throw it away when there is no factory.

Files changed:
M CHANGES.rst
M plone/scale/storage.py
Repository: plone.scale
Branch: refs/heads/1.4.x
Date: 2016-10-22T22:53:44-04:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.scale@bcca32a

modified time can be a long.

Fixes plone.namedfile and plone.app.imaging tests.

Files changed:
M plone/scale/storage.py
Repository: plone.scale
Branch: refs/heads/1.4.x
Date: 2016-10-22T22:53:44-04:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.scale@9d0cf3e

Fix modified scale comparison with offset.

We were subtracting from the wrong value.

Files changed:
M plone/scale/storage.py
Repository: plone.scale
Branch: refs/heads/1.4.x
Date: 2016-10-22T23:07:48-04:00
Author: Jens W. Klein (jensens) <jk@kleinundpartner.at>
Commit: plone/plone.scale@4938b05

Merge pull request #19 from plone/modified-time-compare-14

Various scale storage bug fixes [1.4.x]

Files changed:
M CHANGES.rst
M plone/scale/storage.py
mister-roboto pushed a commit to plone/buildout.coredev that referenced this issue Oct 23, 2016
Branch: refs/heads/1.4.x
Date: 2016-10-22T22:53:44-04:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.scale@05d238a

Avoid TypeErrors when looking for outdated scales.

Fixes plone/plone.scale#12

Files changed:
M CHANGES.rst
M plone/scale/storage.py
Repository: plone.scale
Branch: refs/heads/1.4.x
Date: 2016-10-22T22:53:44-04:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.scale@9d95279

When getting an outdated scale, don't throw it away when there is no factory.

Files changed:
M CHANGES.rst
M plone/scale/storage.py
Repository: plone.scale
Branch: refs/heads/1.4.x
Date: 2016-10-22T22:53:44-04:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.scale@bcca32a

modified time can be a long.

Fixes plone.namedfile and plone.app.imaging tests.

Files changed:
M plone/scale/storage.py
Repository: plone.scale
Branch: refs/heads/1.4.x
Date: 2016-10-22T22:53:44-04:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.scale@9d0cf3e

Fix modified scale comparison with offset.

We were subtracting from the wrong value.

Files changed:
M plone/scale/storage.py
Repository: plone.scale
Branch: refs/heads/1.4.x
Date: 2016-10-22T23:07:48-04:00
Author: Jens W. Klein (jensens) <jk@kleinundpartner.at>
Commit: plone/plone.scale@4938b05

Merge pull request #19 from plone/modified-time-compare-14

Various scale storage bug fixes [1.4.x]

Files changed:
M CHANGES.rst
M plone/scale/storage.py
mister-roboto pushed a commit to plone/buildout.coredev that referenced this issue Oct 23, 2016
Branch: refs/heads/master
Date: 2016-10-22T22:45:43-04:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.scale@8236f40

Avoid TypeErrors when looking for outdated scales.

Fixes plone/plone.scale#12

Files changed:
M CHANGES.rst
M plone/scale/storage.py
Repository: plone.scale
Branch: refs/heads/master
Date: 2016-10-22T22:49:02-04:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.scale@329796c

When getting an outdated scale, don't throw it away when there is no factory.

Files changed:
M CHANGES.rst
M plone/scale/storage.py
Repository: plone.scale
Branch: refs/heads/master
Date: 2016-10-22T22:49:04-04:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.scale@1c3ce6e

modified time can be a long.

Fixes plone.namedfile and plone.app.imaging tests.

Files changed:
M plone/scale/storage.py
Repository: plone.scale
Branch: refs/heads/master
Date: 2016-10-22T22:49:04-04:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.scale@e041d81

Require the `six` package so we can more easily check number types.

On Python 3 `long` has been merged into `int`.

Files changed:
M CHANGES.rst
M plone/scale/storage.py
M setup.py
Repository: plone.scale
Branch: refs/heads/master
Date: 2016-10-22T22:49:04-04:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.scale@111249f

Fix modified scale comparison with offset.

We were subtracting from the wrong value.

Files changed:
M plone/scale/storage.py
Repository: plone.scale
Branch: refs/heads/master
Date: 2016-10-22T23:08:31-04:00
Author: Jens W. Klein (jensens) <jk@kleinundpartner.at>
Commit: plone/plone.scale@9bae0a4

Merge pull request #21 from plone/modified-time-compare-master

Various scale storage bug fixes [master]

Files changed:
M CHANGES.rst
M plone/scale/storage.py
M setup.py
@idgserpro
Copy link

idgserpro commented Jun 13, 2018

Funny, I just got this error in an old Plone 4.3.3 installation and plone.scale 1.3.4.

We were having the same issue as https://github.com/plone/plone.scale/pull/3/files#r10500627, then after seeing https://github.com/plone/plone.scale/pull/4/files we decided to upgrade just plone.scale to 1.3.4 (since we can't do a full upgrade on this specific instance).

But then we're getting the same problem as this issue when trying to replace an image to a new one: we get the same traceback

Module plone.scale.storage, line 73, in scale
TypeError: unsupported operand type(s) for -: 'str' and 'int'

Debugging the values we have:

> /home/user/.buildout/eggs/plone.scale-1.3.4-py2.7.egg/plone/scale/storage.py(73)scale()
     72                 import debug
---> 73                 if value['modified'] < modified - KEEP_SCALE_MILLIS:
     74                     del storage[hash]

ipdb> value['modified']
'1528896720.195449'
ipdb> modified
'1528898146.528053'
ipdb> KEEP_SCALE_MILLIS
86400000

How safe it's to update only plone.scale to 1.4.2 (since your fix When getting an outdated scale, don't throw it away when there is no factory. [maurits] is in there as well)?

@mauritsvanrees
Copy link
Member

Plone 4.3.8 updates plone.scale from 1.3.5 to 1.4.1. So sounds like it should be okay to use 1.4.2.

But it also updates plone.namedfile from 2.0.9 to 3.0.7. Since they are related, you might want to use that one too. I am not sure if it is needed.

It updates plone.app.upgrade from 1.3.18 to 1.3.21, but I don't see any related stuff there, so should be fine to keep the original version.

So: it is worth a shot to update, possibly in combination with plone.namedfile.
Do it on a copy of the site of course, and confirm that it works as expected for existing images (both Archetypes and dexterity based, if relevant for your site), and for adding, editing and deleting images.

@idgserpro
Copy link

Thanks for answering @mauritsvanrees. I haven't even thought about plone.namedfile. Maybe it would be a good idea to check all plone.scale dependencies and do a small research.

In the worst case, a patch to this specific case can be done as well, but I want to avoid that since it gets out of control pretty quickly.

@idgserpro
Copy link

idgserpro commented Jun 14, 2018

Most important changes between versions mentioned by @mauritsvanrees in #12 (comment):

(There's a bug in github rendering, so please add an anchor # before the diff section in the link. Remember to click in the "files" tab.)

1.3.4...1.4.2#diff-d10a7080d4907760fc31685295aba766
1.3.4...1.4.2#diff-4e9d8caa47279e96a075975f073b3f2d

plone.scale 1.4.2 is using a new ScalesDict storage, so upgrading it's a one-way decision.

And in plone.namedfile:

plone/plone.namedfile@2.0.9...3.0.7#diff-3191fc72b422536280e8a8692b6d23d7
plone/plone.namedfile@2.0.9...3.0.7#diff-fd0e8893adafe918855b6e1b4b3dbfa8
plone/plone.namedfile@2.0.9...3.0.7#diff-03f29bbadcdf640341c9061de5a07dcc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants