Opened 12 years ago

Last modified 12 years ago

#18989 closed Cleanup/optimization

Supspicious code in CursorWrapper. — at Version 2

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)

Change History (1)

comment:2 by Claude Paroz, 12 years ago

Description: modified (diff)
Type: UncategorizedCleanup/optimization
Note: See TracTickets for help on using tickets.
Back to Top