exception if fields.py if no _context

Bug #625896 reported by Jim Norman
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Fix Released
Undecided
Anup(SerpentCS)

Bug Description

I made this change some time ago, and no longer have the traceback.

An exception is thrown in osv/fields.py if self._context is False

The following change fixes the problem:

=== modified file 'bin/osv/fields.py'
--- bin/osv/fields.py 2010-08-13 00:23:21 +0000
+++ bin/osv/fields.py 2010-08-20 18:52:39 +0000
@@ -428,7 +428,10 @@
             context = {}
         if self._context:
             context = context.copy()
- context.update(self._context)
+ try:
+ context.update(self._context)
+ except:
+ pass
          if not values:
            values = {}

Revision is 2572, trunk

Related branches

tags: added: trunk
Revision history for this message
xrg (xrg) wrote : Re: [Bug 625896] [NEW] exception if fields.py if no _context

On Saturday 28 August 2010, you wrote:
> I made this change some time ago, and no longer have the traceback.
> context = context.copy()
> - context.update(self._context)
> + try:
> + context.update(self._context)
> + except:
> + pass
> if not values:
> values = {}
>

Just a remark of Pythonic twist:

*Please, avoid catching with "except:", but use "except Exception:" instead. *

The reason is that the first would catch KeyboardInterrupt and SystemExit,
which should never be handled in code like that.

Revision history for this message
Albert Cervera i Areny - http://www.NaN-tic.com (albert-nan) wrote :

A Dissabte, 28 d'agost de 2010, xrg va escriure:
> *Please, avoid catching with "except:", but use "except Exception:"
> instead. *

Well, I don't think try: except: is very appropiate here, even less if you try
to catch all exceptions. I'd simply ensure context is always a dictionary
before executing the statement...

--
Albert Cervera i Areny
http://www.NaN-tic.com
OpenERP Partners
Mòbil: +34 669 40 40 18

http://twitter.com/albertnan
http://albert-nan.blogspot.com

Revision history for this message
Borja López Soilán (NeoPolus) (borjals) wrote :

Instead of the try...except I would just do:

if context and self._context:
    context.update(self._context)

Revision history for this message
Jim Norman (jim-jsnorman) wrote :

I agree with Borja's recommendation.

tags: added: maintenance
Revision history for this message
Anup(SerpentCS) (anup-serpent) wrote :

Hello Guys,

   It has been fixed by revision 2877 <email address hidden>

Thanks a lot for your contributions.
We really do appreciate that. Keep posting.

Changed in openobject-server:
assignee: nobody → Anup (OpenERP) (ach-openerp)
milestone: none → 6.0
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.