Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__set__ always calls __get__ #132

Open
sirex opened this issue May 14, 2012 · 2 comments
Open

__set__ always calls __get__ #132

sirex opened this issue May 14, 2012 · 2 comments

Comments

@sirex
Copy link

sirex commented May 14, 2012

I have implemented some sort of foreign keys automatic fetching. For this I just created custom Property, that automatically returns related document from database when such property is get. But couchdbkit also always calls get on set operation.

Here is example:

  1. I try to set a value to docref property:

    doc.docref = special_docref_object
    
  2. CouchDbKit uses hasattr(self, key) in setattr, what causes get to be called:

    couchdbkit/schema/base.py(182)__setattr__()
    --> 182             if not hasattr( self, key ) ...
    
  3. Now I get unwanted behaviour - database hit, because get is called, but should not be:

    myapp.py(169)__get__()
    --> 169     db.get(value)
    

Maybe

hasattr(self, key)

can be replaces with:

hasattr(self._properties, key)

?

@benoitc
Copy link
Owner

benoitc commented May 21, 2012

getattr doesn't only looks in self.properties though. Maybe this can be changed at this point. I syour property code open somewhere so I can eventually try it?

@sirex
Copy link
Author

sirex commented May 21, 2012

Yes, property class is here:

https://bitbucket.org/sirex/django-sboard/src/517be713b1d7/sboard/models.py#cl-172

But for now, I did a workaround, and made referenced node loading from database only through ref attribute, direct call just returns lazy reference object. So now it solves problem for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants