benoitc / benoitc/couchdbkit

__set__ always calls __get__

Open
#132 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
263
Forks
90
PR merge metrics
No merged PRs in 30d

Description

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)
```

?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.