Zope4 objectValues error!

Hi, I don't undertand !!!
I create a simple python script with "return context.objectValues()"

Systematically, I have a error

This is a traceback:
Traceback (innermost last):

  • Module ZPublisher.WSGIPublisher, line 162, in transaction_pubevents
  • Module ZPublisher.WSGIPublisher, line 359, in publish_module
  • Module ZPublisher.WSGIPublisher, line 264, in publish
  • Module ZPublisher.HTTPResponse, line 1098, in setBody
  • Module ZPublisher.HTTPResponse, line 528, in setBody

AttributeError: index

I tried this script into zope2, and no problem. What is happening !
can someone explain to me why Zope4 is so different from Zope2? Is this a difference induced by the version of python?

Weird, this morning I retested, and it works out of the folder I originally tried.
No problem then.

When I tried to reproduce it, I had the same problem.

Maybe it depends on the folder/item you call it?

Do you see any differences in what you did today and the last time?

In fact there is a problem. If we try to directly return a list of objects we get an error, on the other hand if we return a list of id of objects it works.

Works:
results=
datas = context.objectValues(['Page Template'])
for obj in datas:
if obj.getProperty('published'):
results.append(obj.id)
return results

But not this:
results=
datas = context.objectValues(['Page Template'])
for obj in datas:
if obj.getProperty('published'):
results.append(obj)
return results

:frowning:

we can do:
text = context.objectValues()
print(text)
return printed

we can't do:
text = context.objectValues()
return text

Zope objects are very complex -- too complex that the response could directly handle it. That''s why return f.objectValues() fails while return f.objectIds() works.

ok i can understand. However I was surprised because it works with Zope2.
It also means that I will have a lot of refactoring to migrate to zope4.

Thanks

Thanks for clarifying, Dieter!

That was the missing link. The return statement in a Script(Python) directly generates a response!

As of the differences between Zope 2 and Zope 4... I do not know whether this is relevant here, but I noticed that __repr__ of my Zope objects has changed, from something useful, to something :roll_eyes:, so I had to create custom __repr__ for all my classes.