Commit 21f85a6f authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki Committed by Jérome Perrin

Zope2: use func_code if __code__ is missing, that is the case for Script (Python).

parent 55dc4b19
......@@ -165,6 +165,8 @@ class Alarm(XMLObject, PeriodicityMixin):
tag = activate_kw['tag']
method = getattr(self, method_id)
func_code = method.__code__
if func_code is None: # BBB Zope2
  • Hi @kazuhiko , I hit a problem today here. I got an Attribute error on func_code = method.__code__

    Maybe it's better to first check if the method had this code attribute? Like: if hasattr(method, '__code__'): func_code = method.__code__

  • Hi @Sokhoyan if it's possible for you, another solution is to install a more recent slapos software release and use Zope4.

    Keeping Zope2 support is also an "experiment" to know if generally it's useful to keep support for the previous version when we update to a new incompatible version, so if you really need to keep using an old version of slapos with a new version of ERP5, it's interesting to know.

    Edited by Jérome Perrin
  • BTW you are right and this is the same problem as discussed below, there was a fixup commit ( 7a2c616e ) but it does not seem to cover this. If you want to push a commit to use hasattr it's welcome

  • @jerome I needed this way at the moment because I wanted to have a similar instance as woelfel-web-monitoring production, which we didn't update yet. In general I agree that the best way it to have all the compatible versions, but anyway if this code is here we should make sure that it works :)

    Yup, I'll add this fix.

  • I added respective fix with a3437c62 since I also run into the same issue :)

  • Thanks. Independently from this, the best for you is probably to update the software release to use Zope 4.

  • @jerome yess I know we should asap update it to zope 4, but since we update from a very old SR (wwm) and it already took very long to make this functioning, we want to first apply current state before moving further (to zope4).

  • I see, that makes sense. Thanks for explaining and good luck with this upgrade ;)

Please register or sign in to reply
func_code = method.func_code
try:
has_kw = func_code.co_flags & CO_VARKEYWORDS
except AttributeError:
......
......@@ -181,7 +181,10 @@ class Predicate(XMLObject):
try:
result = method(self)
except TypeError:
if method.__code__.co_argcount != isinstance(method, MethodType):
func_code = method.__code__
if func_code is None: # BBB Zope2
func_code = method.func_code
if func_code.co_argcount != isinstance(method, MethodType):
raise
# backward compatibilty with script that takes no argument
warn('Predicate %s uses an old-style method (%s) that does not'
......
......@@ -1451,7 +1451,10 @@ class Catalog(Folder,
if meta_type in self.HAS_ARGUMENT_SRC_METATYPE_SET:
return method.arguments_src.split()
elif meta_type in self.HAS_FUNC_CODE_METATYPE_SET:
return method.__code__.co_varnames[:method.__code__.co_argcount]
func_code = method.__code__
if func_code is None: # BBB Zope2
  • @kazuhiko it seems the condition is not correct (for zope 2), it's not None, it causes an attribute error, see https://softinst161127.host.vifib.net/cvt-MKlV4nLOOm/erp5/test.test_erp5.TestCloudoooDefaultParameter_zeo.setUpClass/inst/cd5/var/log/zope-0-event.log

      File "/srv/slapgrid/slappart33/t/cvt/i/0/tmp/soft/82a1a2a723c2570be7e099af333d6b5b/parts/erp5/product/ZSQLCatalog/ZSQLCatalog.py", line 816, in catalogObjectList
        **kw
      File "/srv/slapgrid/slappart33/t/cvt/i/0/tmp/soft/82a1a2a723c2570be7e099af333d6b5b/parts/erp5/product/ZSQLCatalog/SQLCatalog.py", line 1275, in catalogObjectList
        idxs=idxs)
      File "/srv/slapgrid/slappart33/t/cvt/i/0/tmp/soft/82a1a2a723c2570be7e099af333d6b5b/parts/erp5/product/ZSQLCatalog/SQLCatalog.py", line 1431, in _catalogObjectList
        for x in self._getCatalogMethodArgumentList(method)
      File "/srv/slapgrid/slappart33/t/cvt/i/0/tmp/soft/82a1a2a723c2570be7e099af333d6b5b/parts/erp5/product/ZSQLCatalog/SQLCatalog.py", line 1454, in _getCatalogMethodArgumentList
        func_code = method.__code__
    AttributeError: __code__

    /cc @rafael

  • ( probably same for the func_code = script.__code__ below )

  • Yes, I had this problem. Thx jerome.

Please register or sign in to reply
func_code = method.func_code
return func_code.co_varnames[:func_code.co_argcount]
# Note: Raising here would completely prevent indexation from working.
# Instead, let the method actually fail when called, so _catalogObjectList
# can log the error and carry on.
......@@ -1838,6 +1841,8 @@ class Catalog(Folder,
search_key = self.getSearchKey(key, 'RelatedKey')
else:
func_code = script.__code__
if func_code is None: # BBB Zope2
func_code = script.func_code
search_key = (
AdvancedSearchKeyWrapperForScriptableKey if (
# 5: search_value (under any name), "search_key", "group",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment