#18989: Supspicious code in CursorWrapper.
-------------------------------------+-------------------------------------
     Reporter:  zimnyx               |                    Owner:  nobody
         Type:                       |                   Status:  new
  Cleanup/optimization               |                  Version:  1.4
    Component:  Database layer       |               Resolution:
  (models, ORM)                      |             Triage Stage:
     Severity:  Normal               |  Unreviewed
     Keywords:                       |      Needs documentation:  0
    Has patch:  0                    |  Patch needs improvement:  0
  Needs tests:  0                    |                    UI/UX:  0
Easy pickings:  0                    |
-------------------------------------+-------------------------------------
Changes (by claudep):

 * type:  Uncategorized => Cleanup/optimization


Old description:

> Shouldn't it be __getattribute__() ?
> If we want set_dirty() to be called on every access to 'db' and 'cursor'
> attributes, definitely yes. Otherwise "if attr in self.__dict__: ..."
> should be removed.
> {{{
> # Django 1.4
> class CursorWrapper(object):
>     def __init__(self, cursor, db):
>         self.cursor = cursor
>         self.db = db
>
>     def set_dirty(self):
>         if self.db.is_managed():
>             self.db.set_dirty()
>
>     def __getattr__(self, attr):
>         self.set_dirty()
>         if attr in self.__dict__:
>             return self.__dict__[attr]
>         else:
>             return getattr(self.cursor, attr)
> }}}

New description:

 Shouldn't it be `__getattribute__()` ?
 If we want set_dirty() to be called on every access to 'db' and 'cursor'
 attributes, definitely yes. Otherwise "if attr in self.__dict__: ..."
 should be removed.
 {{{
 # Django 1.4
 class CursorWrapper(object):
     def __init__(self, cursor, db):
         self.cursor = cursor
         self.db = db

     def set_dirty(self):
         if self.db.is_managed():
             self.db.set_dirty()

     def __getattr__(self, attr):
         self.set_dirty()
         if attr in self.__dict__:
             return self.__dict__[attr]
         else:
             return getattr(self.cursor, attr)
 }}}

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/18989#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to