← Back to team overview

openerp-india team mailing list archive

[Bug 1263434] [NEW] mail_thread message_route misleading model

 

Public bug reported:

If default server action for incoming mail server is crm.helpdesk and message is sent with an id:
1387684209.265750885009766.517219991153385-openerp-215-account.invoice@server

This will end up trying to create a new account.invoice obcject and
failing with Null required values (like account_id).

After lots of messages and debugging - the problem is found.

    def message_route(self, cr, uid, message, model=None, thread_id=None,
                      custom_values=None, context=None):

[...]

        if ref_match:
            thread_id = int(ref_match.group(1))
            model = ref_match.group(2) or model
            model_pool = self.pool.get(model)
            if thread_id and model and model_pool and model_pool.exists(cr, uid, thread_id) \
                and hasattr(model_pool, 'message_update'):
                _logger.info('Routing mail from %s to %s with Message-Id %s: direct reply to model: %s, thread_id: %s, custom_values: %s, uid: %s',
                                email_from, email_to, message_id, model, thread_id, custom_values, uid)
                return [(model, thread_id, custom_values, uid)]

[ here the ref_match returns something and local model is changed for matched model,
there is no existing thread id and this if statement does not return ! 
and later in the same scope of method]


        # 3. Fallback to the provided parameters, if they work
        model_pool = self.pool.get(model)
        if not thread_id:
            # Legacy: fallback to matching [ID] in the Subject
            match = tools.res_re.search(decode_header(message, 'Subject'))
            thread_id = match and match.group(1)
            # Convert into int (bug spotted in 7.0 because of str)
            try:
                thread_id = int(thread_id)
            except:
                thread_id = False
        assert thread_id and hasattr(model_pool, 'message_update') or hasattr(model_pool, 'message_new'), \
            "No possible route found for incoming message from %s to %s (Message-Id %s:)." \
            "Create an appropriate mail.alias or force the destination model." % (email_from, email_to, message_id)
        if thread_id and not model_pool.exists(cr, uid, thread_id):
            _logger.warning('Received mail reply to missing document %s! Ignoring and creating new document instead for Message-Id %s',
                                thread_id, message_id)
            thread_id = None
        _logger.info('Routing mail from %s to %s with Message-Id %s: fallback to model:%s, thread_id:%s, custom_values:%s, uid:%s',
                        email_from, email_to, message_id, model, thread_id, custom_values, uid)
        return [(model, thread_id, custom_values, uid)]


[ here we have not the default model 'crm.helpdesk' but account.invoice with no thread_id
so the returned route will be: [(u'account.invoice', None, None, 1)] ] - pretty wrong !


solution:

        if ref_match:
            thread_id = int(ref_match.group(1))
            model_match = ref_match.group(2) or model
            model_pool = self.pool.get(model_match)
            if thread_id and model_match and model_pool and model_pool.exists(cr, uid, thread_id) \
                and hasattr(model_pool, 'message_update'):
                _logger.info('Routing mail from %s to %s with Message-Id %s: direct reply to model: %s, thread_id: %s, custom_values: %s, uid: %s',
                                email_from, email_to, message_id, model_match, thread_id, custom_values, uid)
                return [(model_match, thread_id, custom_values, uid)]

this is openobject-addons revno: 9701

** Affects: openobject-addons
     Importance: Undecided
         Status: New


** Tags: 7.0

-- 
You received this bug notification because you are a member of OpenERP
Indian Team, which is subscribed to OpenERP Addons.
https://bugs.launchpad.net/bugs/1263434

Title:
  mail_thread message_route misleading model

Status in OpenERP Addons (modules):
  New

Bug description:
  If default server action for incoming mail server is crm.helpdesk and message is sent with an id:
  1387684209.265750885009766.517219991153385-openerp-215-account.invoice@server

  This will end up trying to create a new account.invoice obcject and
  failing with Null required values (like account_id).

  After lots of messages and debugging - the problem is found.

      def message_route(self, cr, uid, message, model=None, thread_id=None,
                        custom_values=None, context=None):

  [...]

          if ref_match:
              thread_id = int(ref_match.group(1))
              model = ref_match.group(2) or model
              model_pool = self.pool.get(model)
              if thread_id and model and model_pool and model_pool.exists(cr, uid, thread_id) \
                  and hasattr(model_pool, 'message_update'):
                  _logger.info('Routing mail from %s to %s with Message-Id %s: direct reply to model: %s, thread_id: %s, custom_values: %s, uid: %s',
                                  email_from, email_to, message_id, model, thread_id, custom_values, uid)
                  return [(model, thread_id, custom_values, uid)]

  [ here the ref_match returns something and local model is changed for matched model,
  there is no existing thread id and this if statement does not return ! 
  and later in the same scope of method]

  
          # 3. Fallback to the provided parameters, if they work
          model_pool = self.pool.get(model)
          if not thread_id:
              # Legacy: fallback to matching [ID] in the Subject
              match = tools.res_re.search(decode_header(message, 'Subject'))
              thread_id = match and match.group(1)
              # Convert into int (bug spotted in 7.0 because of str)
              try:
                  thread_id = int(thread_id)
              except:
                  thread_id = False
          assert thread_id and hasattr(model_pool, 'message_update') or hasattr(model_pool, 'message_new'), \
              "No possible route found for incoming message from %s to %s (Message-Id %s:)." \
              "Create an appropriate mail.alias or force the destination model." % (email_from, email_to, message_id)
          if thread_id and not model_pool.exists(cr, uid, thread_id):
              _logger.warning('Received mail reply to missing document %s! Ignoring and creating new document instead for Message-Id %s',
                                  thread_id, message_id)
              thread_id = None
          _logger.info('Routing mail from %s to %s with Message-Id %s: fallback to model:%s, thread_id:%s, custom_values:%s, uid:%s',
                          email_from, email_to, message_id, model, thread_id, custom_values, uid)
          return [(model, thread_id, custom_values, uid)]

  
  [ here we have not the default model 'crm.helpdesk' but account.invoice with no thread_id
  so the returned route will be: [(u'account.invoice', None, None, 1)] ] - pretty wrong !


  solution:

          if ref_match:
              thread_id = int(ref_match.group(1))
              model_match = ref_match.group(2) or model
              model_pool = self.pool.get(model_match)
              if thread_id and model_match and model_pool and model_pool.exists(cr, uid, thread_id) \
                  and hasattr(model_pool, 'message_update'):
                  _logger.info('Routing mail from %s to %s with Message-Id %s: direct reply to model: %s, thread_id: %s, custom_values: %s, uid: %s',
                                  email_from, email_to, message_id, model_match, thread_id, custom_values, uid)
                  return [(model_match, thread_id, custom_values, uid)]

  this is openobject-addons revno: 9701

To manage notifications about this bug go to:
https://bugs.launchpad.net/openobject-addons/+bug/1263434/+subscriptions


Follow ups

References