Skip to content
This repository has been archived by the owner on Jul 20, 2018. It is now read-only.

redisco.models.attributes.ReferenceField.__get__ does not read from instance #2

Closed
clayg opened this issue Jul 30, 2010 · 3 comments
Closed

Comments

@clayg
Copy link

clayg commented Jul 30, 2010

given app/models.py as:

from redisco import models

class Department(models.Model):
    name = models.Attribute(required=True)

class Person(models.Model):
    name = models.Attribute(required=True)
    #manager = models.ReferenceField('Person', related_name='underlings')
    department = models.ReferenceField(Department)

You can see that ReferenceField is correctly handling the _manager_id in set, but the get is caching the referenced model on the ReferenceField instance instead of the Model instance:

>>> from app import models
>>> d1 = models.Department(name='Accounting')
>>> d1.save()
True
>>> d2 = models.Department(name='Billing')
>>> d2.save()
True
>>> p1 = models.Person(name='Joe', department=d1)
>>> p1.save()
True
>>> p1
<Person:1 {'department': <Department:1 {'name': 'Accounting'}>, 'name': 'Joe', 'department_id': '1'}>
>>> p2 = models.Person(name='Jack', department=d2)
>>> p2.save()
True
>>> p2
<Person:2 {'department': <Department:1 {'name': 'Accounting'}>, 'name': 'Jack', 'department_id': '2'}>

N.B.

>>> p2.department_id
'2'
>>> p2.department.id
'1'
@clayg
Copy link
Author

clayg commented Jul 30, 2010

I don't think it was intentional for this test to pass:

        Character.objects.create(n=32, m='a', word=word)
        Character.objects.create(n=33, m='b', word=word)
        Character.objects.create(n=34, m='c', word=word)
        Character.objects.create(n=34, m='d')
        for char in Character.objects.all():
            self.assertEqual(word, char.word)

Later we assert:
self.assertTrue(d not in word.character_set)

So I'm going to change this test.

@clayg
Copy link
Author

clayg commented Jul 30, 2010

fixed in fork:
http://github.com/clayg/redisco

submitted pull request.

@iamteem
Copy link
Owner

iamteem commented Jul 31, 2010

Thanks! :D

xwssole pushed a commit to xwssole/redisco that referenced this issue Oct 10, 2012
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants