Products.cmfplone: Plone 5.2: `Using len() is deprecated.` error

Created on 21 Nov 2019  路  8Comments  路  Source: plone/Products.CMFPlone

Plone 5.2 on Python 3.7.3 on Ubuntu 18.04 LTS (and on macOS Catalina):

I get this error when viewing the front page of a brand new site, when running bin/instance fg:

<string>:387: DeprecationWarning: Using len() is deprecated. Use thelengthattribute for the size of the current page, which is what we return now. Use thesequence_lengthattribute for the size of the entire sequence.

That is the entirety of the message; there is no stack trace

question

All 8 comments

Bah, unable to reproduce now.

The deprecation warning comes from https://github.com/plone/Products.CMFPlone/blob/master/Products/CMFPlone/PloneBatch.py#L24 but seems to be triggered not with a plain old Plone site but at least if collective.lineage 2.1.1 is installed and you try to view a folder which has been made into a subsite.

Can we remove this deprecation warning? What is its point?

@tomgross this was your addition :) Is this deprecation still useful? (maybe it is since something in lineage must be invoking it)

Hi @tkimnguyen
My wild guess would be it was deprecated because it could be confusing what is meant: batch length or full length. This thesis seems to be supported my @mauritsvanrees comment here:
https://github.com/plone/Products.CMFPlone/commit/a66ed5462e701fe61726db6566d30afefd4326ea

I still guess the deprecation was to avoid confusion, like I wrote in the commit message that Tom points too.

In your lineage line, it looks like sites is a standard list without batching. Maybe the catalog always returns a batch, but I doubt it. Are you sure this is really the place that triggers it?

I expect that sites always has size 2 or higher at that point, because I cannot imagine that the condition for root url not in sites urls is ever False: the portal object is never in the catalog. Well, maybe when we use dexterity for the site root, but that is for Plone 6.

Workaround would be to change if len(sites) <= 1: to an elif. So you have roughly this:

if not sites:
    return []
# So we have at least one site.
if root_url not in [s['url'] for s in sites]:
    # and we insert a second one, so we know we have enough
    sites.insert(...)
elif len(sites) <= 1:
    # Checking this condition would still trigger the deprecation warning,
    # but I don't think you ever get here.
    return []
return sites

Yeah, I can't see how sites would ever have less than size 2. Thanks! I'm going to remove that check entirely.

Bah, of course now I'm seeing it show up elsewhere in the code:

/Users/kimnguyen/src/collective.lineage/eggs/plone.resource-2.1.1-py3.7.egg/plone/resource/manifest.py:82: DeprecationWarning: The SafeConfigParser class has been renamed to ConfigParser in Python 3.2. This alias will be removed in future versions. Use ConfigParser directly instead.
  parser = SafeConfigParser()
/Users/kimnguyen/src/collective.lineage/var/cache/fcf96591fab18feb300fb317a88f3257.py:388: 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. 
  if __condition:
/Users/kimnguyen/src/collective.lineage/eggs/Chameleon-3.6.2-py3.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 ()
/Users/kimnguyen/src/collective.lineage/var/cache/9cca86eab3dcebcf4379f6c4c350e789.py:126: 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. 
  if __condition:
Was this page helpful?
0 / 5 - 0 ratings

Related issues

hvelarde picture hvelarde  路  4Comments

pbauer picture pbauer  路  3Comments

mauritsvanrees picture mauritsvanrees  路  4Comments

davisagli picture davisagli  路  4Comments

djay picture djay  路  6Comments