Odoo Help


cursor object has no attribute 'write'?

on 4/24/13, 4:34 PM 2,049 views

The traceback complains about sql_db.py line 358 in __getattr__ and before that it is line 162 in wrapper which is inside the decorator function 'check'. I agree with it, class Cursor has no attribute 'write'. However, my function (app_approve) is trying to write and it is in the traceback prior to the above. I just don't understand how it thinks I am trying to call 'write' on the cursor when I'm explicitly calling self.write. Or am I not myself here? This is getting too metaphysical anybody have any ideas?

def _create_application_history(self, cr, uid, ids, vals, context=None):
    """ Creates new application history objects """
    current_application = self.browse(cr, uid, ids, context=context)[0]
    # we are only working with a single record here 
    vals['application_id'] = current_application.id
    vals['current_status'] = current_application.state
    vals['completion'] = current_application.completion
    vals['note'] = current_application.note
    # get id from the ORM browse record since ORM can't recognize its own objects
    vals['dbe_specialist'] = current_application.dbe_specialist.id
    vals['onsite_visit_date'] = current_application.onsite_visit_date
    vals['onsite_visit_notes'] = current_application.onsite_visit_notes
    vals['visit_approved'] = current_application.visit_approved
    vals['docs_completed'] = current_application.docs_completed
    # get application history object and call its create
    _logger.debug("Application history create called with ids %s and vals %s", str(ids), str(vals))
    history_id = self.pool.get('dbe.application.history').create(cr, uid, vals, context=context)
    return history_id

def _transaction_history(func):
    """ Decorator function for historical logging of transactions """
    @functools.wraps(func) # ensuring we still have a name after wrapping
    def wrapped(self, cr, uid, ids, vals, context=None):
        func_name = func.__name__
        # if the wrapped function name matches a transaction type create a corresponding history record
        if func_name in _transaction_types.keys():
            vals['transaction_type'] = _transaction_types[func_name]                
            history_id = self._create_application_history(cr, uid, ids, vals, context)

        if history_id:
            _logger.debug("Application history created for transaction type %s with record #%d", _transaction_types[func_name], history_id)
        # call wrapped function without explicit self
        return func(cr, uid, ids, vals, context)
    return wrapped

def app_approve(self, cr, uid, ids, context={}):
    """ Setting the application record state to 'approve' from form action """
    return self.write(cr, uid, ids, {'state': 'approve'}, context=context)
On 4/24/13, 5:47 PM

Fixed! This...

def app_approve(self, cr, uid, ids, context={}):

Should have been this...

def app_approve(self, cr, uid, ids, vals, context):

It was an impedance mismatch because either vals was missing or I had multiple values for context (or both). I needed to pass self through the wrapper and not return the wrapper as self because at the end of it all I was attempting self.write anyway.

Also, I had an unrelated mistake in original code for _transaction_history instead of passing vals to the create method pass vals.copy() to prevent resetting values in vals with values for self.


Francesco OpenCode

--Francesco OpenCode--
Francesco OpenCode
| 5 7 9
Grottaglie, Italy
--Francesco OpenCode--

Italian Odoo (OpenERP) Modules Developer LINKEDIN: http://www.linkedin.com/in/francescoapruzzese

Francesco OpenCode
On 4/24/13, 4:41 PM

Self has write but cr not, if you call this function

return func(cr, uid, ids, vals, context)

you obtain an error becase the firts parameter (cr) must be self

return self.func(cr, uid, ids, vals, context)

but then it complains: line 345 in wrapped return func(self, cr, uid, vals, context) TypeError: app_approve() takes at most 5 arguments (6 given). So self is passed anyway and the reason I didn't call with it before. This is normal from wrapped functions? Seems like it shouldn't be...

on 4/24/13, 4:51 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 4/24/13, 4:34 PM
Seen: 2049 times
Last updated: 3/16/15, 8:10 AM