Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#18989 closed Cleanup/optimization (fixed)

Supspicious code in CursorWrapper.

Reported by: Piotr Czachur Owned by: nobody
Component: Database layer (models, ORM) Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Claude Paroz)

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)

Attachments (1)

18989-1.diff (639 bytes ) - added by Claude Paroz 12 years ago.
Optimize CursorWrapper getattr

Download all attachments as: .zip

Change History (6)

comment:2 by Claude Paroz, 12 years ago

Description: modified (diff)
Type: UncategorizedCleanup/optimization

comment:3 by Claude Paroz, 12 years ago

Triage Stage: UnreviewedAccepted

Current coverage report for this file seems to give you credit: http://ci.djangoproject.com/job/Django%20Coverage/HTML_Coverage_Report/_var_lib_jenkins_jobs_Django%20Coverage_workspace_django_db_backends_util.html

I'd rather suppress the if attr in self.__dict__ part, as we mainly want to catch the calls to execute/executemany on this class' instances.

by Claude Paroz, 12 years ago

Attachment: 18989-1.diff added

Optimize CursorWrapper getattr

comment:4 by Claude Paroz, 12 years ago

Has patch: set

comment:5 by Claude Paroz <claude@…>, 12 years ago

Resolution: fixed
Status: newclosed

In 8c69278764ae31b0cd495d21b84444bf2471c103:

Fixed #18989 -- Removed unused condition in CursorWrapper

Thanks zimnyx for the report.

comment:6 by Claude Paroz <claude@…>, 12 years ago

In a023952e10092775215aeb2277d2fe3af5794e3b:

[1.5.x] Fixed #18989 -- Removed unused condition in CursorWrapper

Thanks zimnyx for the report.
Backport of 8c6927876 from master.

Note: See TracTickets for help on using tickets.
Back to Top