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

Property with leading underscore and independent database property name is not written to database #279

Closed
mjmare opened this issue Oct 22, 2017 · 3 comments
Labels

Comments

@mjmare
Copy link

@mjmare mjmare commented Oct 22, 2017

I wanted to have a read-only property that would be written to the database but set when setting another property.

class FileNode(BaseNode):
    file_id = StringProperty(db_property='content')
    _content_type = StringProperty(db_property='content_type')
    :
    (getter and setter for content)
    (getter for content_type)

When using this Node type the content property would be set by the user (through the setter) and the content_type derived in that process.

All went well except that the value for the content_type was not present in the node in the database.
It turn out that changing _content_type to content_type_ fixes it.
So properties with a leading underscore seem to be ignored, which was unexpected.

@robinedwards

This comment has been minimized.

Copy link
Collaborator

@robinedwards robinedwards commented Oct 23, 2017

Thanks for spotting this, it really should be documented somewhere, its due to the way the internals work.

@manoadamro

This comment has been minimized.

Copy link
Contributor

@manoadamro manoadamro commented Mar 8, 2018

@robinedwards

This works:

    _dob = DateProperty(db_property='dob')

    @property
    def dob(self):

        return parse_date_to_iso8601(self._dob)

    @dob.setter
    def dob(self, value):

        self._dob = parse_iso8601_to_date(value)

But this does not:

    _lived_from = DateProperty(db_property='lived_from')

    @property
    def lived_from(self):
      
        return parse_date_to_iso8601(self._lived_from)

    @lived_from.setter
    def lived_from(self, value):

        self._lived_from = parse_iso8601_to_date(value)

I'm constructing the objects like this:
Model(**{"lived_from": "1970-01-01"})

Using log statements i can see that the setter never gets called, causing the getter to return None all the time.

Changing from _lived_from to lived_from_ didn't change anything for me :(

@aanastasiou

This comment has been minimized.

Copy link
Collaborator

@aanastasiou aanastasiou commented Apr 25, 2019

@mjmare Thank you, this has now been addressed in the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.