zopefoundation / zope.index

Indices for using with catalog like text, field, etc.
Other
10 stars 12 forks source link

TypeError: 'float' object cannot be interpreted as an integer #38

Closed WuShell closed 7 months ago

WuShell commented 2 years ago

BUG/PROBLEM REPORT (OR OTHER COMMON ISSUE)

What I did:

Upgrade a development env that was working just fine in python 3.9.x to 3.10.4 then ran tests on my code base (pyramid web app that uses traversal, ZODB and some zope libs)

What I expect to happen:

Tests to pass, code to run as it ran with 3.9

What actually happened:

Whenever I have to query the catalog, an exception is raised. This is an example on a test failure:

Traceback (most recent call last):                                                                                                                                                                                                      
  File "/usr/local/lib/python3.10/doctest.py", line 1346, in __run                                                                                                                                                                      
    exec(compile(example.source, filename, "single",                                                                                                                                                                                    
  File "<doctest migrations.31.migrate[33]>", line 2, in <module>                                                                                                                                                            
  File "/home/wu/REPO/models/scan.py", line 141, in search                                                                                                                        
    res = self.query(                                                                                                                                                                                                                   
  File "/home/wu/REPO/catalog.py", line 208, in query                                                                                                                             
    number, results = catalog.query(query, reverse=reverse)                                                                                                                                                                             
  File "/home/wu/ENVS/3.10/lib/python3.10/site-packages/repoze/catalog/catalog.py", line 153, in query                                                                                                   
    results = queryobject._apply(self, names)                                                                                                                                                                                           
  File "/home/wu/ENVS/3.10/lib/python3.10/site-packages/repoze/catalog/query.py", line 95, in _apply                                                                                                     
    return index.applyContains(self._get_value(names))                                                                                                                                                                                  
  File "/home/wu/ENVS/3.10/lib/python3.10/site-packages/repoze/catalog/indexes/text.py", line 74, in applyContains                                                                                       
    return self.apply(value)                                                                                                                                                                                                            
  File "/home/wu/ENVS/3.10/lib/python3.10/site-packages/zope/index/text/textindex.py", line 73, in apply                                                                                                 
    results = tree.executeQuery(self.index)  
  File "/home/wu/ENVS/3.10/lib/python3.10/site-packages/zope/index/text/parsetree.py", line 123, in executeQuery                                                                                         
    return index.search_phrase(self.getValue())                                                                     
  File "/home/wu/ENVS/3.10/lib/python3.10/site-packages/zope/index/text/baseindex.py", line 203, in search_phrase
    scores = self._search_wids(wids)                                                                                                                                                                                                    
  File "/home/wu/ENVS/3.10/lib/python3.10/site-packages/zope/index/text/okapiindex.py", line 347, in _c_search_wids
    score(result, items, docid2len, idf, meandoclen)
TypeError: 'float' object cannot be interpreted as an integer

What version of Python and Zope/Addons I am using:

pyramid              1.10.8
pyramid-debugtoolbar 4.9   
pyramid-jinja2       2.10       
pyramid-ldap3        0.5   
pyramid-mailer       0.15.1
pyramid-mako         1.1.0
pyramid-retry        2.1.1                                                                                          
pyramid-tm           2.5  
pyramid-zodbconn     0.8.1
zc.lockfile          2.0
ZConfig              3.6.0
zdaemon              4.3
ZEO                  5.3.0
ZODB                 5.7.0
ZODB3                3.11.0
zodbpickle           2.3
zodburi              2.5.0
zope.component       5.0.1
zope.deprecation     4.4.0
zope.event           4.5.0
zope.hookable        5.1.0
zope.index           5.1.0
zope.interface       5.4.0

More info/research.

Looking a bit at the 3.10.x changelog (https://docs.python.org/3/whatsnew/3.10.html) There is this point here:

Builtin and extension functions that take integer arguments no longer accept Decimals, Fractions and other objects that can be converted to integers only with a loss (e.g. that have the int() method but do not have the index() method). (Contributed by Serhiy Storchaka in bpo-37999.)

Which points to this bugfix: https://github.com/python/cpython/issues/82180

Maybe that is causing this behaviour?

icemac commented 2 years ago

@WuShell Hi, you are using zope.index version which does not support Python 3.10. Please update to version 5.2.0 and report back whether this fixes your problem.

icemac commented 7 months ago

I am closing this old issue. Feel free to re-open it if there are any news about the topic.