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.

-- 
You received this message because you are subscribed to the Google Groups 
"tryton" group.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tryton/d37f2ea2-71a7-42eb-9b97-2638e79d85a6%40googlegroups.com.

Reply via email to