1. Thomas Weholt
  2. dse4
  3. Issues
Issue #2 on hold

Assigning value to a read only property

created an issue

self.cursor is read only property so we can't assign a value to it

def _execute(self, sql, fieldvalues, many=True):
    self.sql_calls += 1
        if many:
            self.cursor.executemany(sql, fieldvalues)
            self.cursor.execute(sql, fieldvalues)
       self.cursor = self.connection.cursor()
        if many:
            self.cursor.executemany(sql, fieldvalues)
            self.cursor.execute(sql, fieldvalues)

fix for it adding setter

def cursor(self, value):
    self.cached_cursor = value

Comments (8)

  1. Thomas Weholt repo owner

    Are you sure this is a problem? I mean the code:

        def cursor(self):
            if not CACHE_CURSOR:
                return connection.cursor()
            return self.cached_cursor

    means the self.cursor is a property with both a getter and a setter and I've not had any problem with this.

    Can you provide any example of a stacktrace showing an exception being thrown etc?

  2. Thomas Weholt repo owner

    Nooooo! Can you tell me what kind of environment you were using? What kind/version of operating system, django and python version, database etc? Were you using the django-debug-toolbar?

  3. jetfix reporter

    Property decorator makes read-only attributes:

    "This makes it possible to create read-only properties easily using property() as a decorator" (doc ) You can emulate error like this:

    class A(object):
        def __init__(self):
            self.cached_cursor = 1
        def cursor(self):
            return self.cached_cursor
    In [16]: b = A()
    In [17]: b.cursor = 2
    AttributeError Traceback (most recent call last)
    <ipython-input-17-10dc111d7b3c> in <module>()
    ----> 1 b.cursor = 2

    As for enviroment, i used: py 2.7, django 1.5, postgres 9.1, ubuntu 13.10 )

  4. Log in to comment