Hi all,
I have a piece of code that uses cursor, but looks like cursor is removed from Trytond 4. When I use this code inside of Tryton 4, I get this error:
Traceback (most recent call last):
File "/trytond/wsgi.py", line 47, in dispatch_request
return endpoint(request, **request.view_args)
File "/trytond/protocols/dispatcher.py", line 59, in rpc
request, database_name, *request.params)
File "/trytond/wsgi.py", line 39, in auth_required
return wrapped(*args, **kwargs)
File "/trytond/protocols/dispatcher.py", line 40, in wrapper
return func(request, pool, *args, **kwargs)
File "/trytond/protocols/dispatcher.py", line 201, in _dispatch
result = rpc.result(meth(*c_args, **c_kwargs))
File "/trytond/model/modelsql.py", line 762, in read
getter_results = field.get(ids, cls, field_list, values=result)
File "/trytond/model/fields/function.py", line 92, in get
return dict((name, call(name)) for name in names)
File "/trytond/model/fields/function.py", line 92, in <genexpr>
return dict((name, call(name)) for name in names)
File "/trytond/model/fields/function.py", line 84, in call
return method(records, name)
File "/trytond/modules/training/opportunity.py", line 92, in get_description_length
cursor = Transaction().cursor
AttributeError: 'Transaction' object has no attribute 'cursor'
This is the code:
@classmethod
def get_description_length(cls, opportunities, name):
cursor = Transaction().cursor
opportunity = cls.__table__()
query = opportunity.select(
opportunity.id, CharLength(opportunity.description),
where=opportunity.id.in_([
o.id for o in opportunities]))
cursor.execute(*query)
return {id: length for id, length in cursor.fetchall()}
We used cursor to execute query, now obviously there should be some replacement. I tried to look at the source to find out what that could be, but there were too many problems.
The class Transaction as defined in trytond/transaction.py indeed contained attribute cursor and in new version this attribute is missing. I need a replacement way to execute the query as can be seen from the provided excerpt of my code.
Please help.