3

I have a hybrid property like this

@hybrid_property
def address(self):
    return ', '.join([
        self.address_street,
        self.address_city,
        self.address_state,
        self.address_zip
        ])

@address.setter
def address(self, address):
    g = geocoder.google(address)
    if g.street_number and g.street_name:
        self.address_street = g.street_number + ' ' + g.street_name
    if g.city:
        self.address_city = g.city
    if g.state:
        self.address_state = g.state
    if g.postal:
        self.address_zip = g.postal
    if g.latlng:
        self.address_lat = g.lat
        self.address_lng = g.lng

@address.expression
def address(cls):
    return cls.address_street + ', ' + cls.address_city + ', ' + cls.address_state + ', ' + cls.address_zip

Using a basic Flask-Restless API...

manager = APIManager(app, flask_sqlalchemy_db=db)
member_bp = manager.create_api(
    Member,
    collection_name='members',
    methods=['GET', 'POST', 'PATCH'],
    include_columns=[
        'id',
        'first_name',
        'last_name',
        'email',
        'created_at',
        'signup_code',
        ]
    )

But Flask-Restless gives me a 400 and says Model does not have field 'address'. I have another hybrid_property that I am setting as well, but it doesn't complain about that. I can't figure out what's wrong with this hybrid_property.

The weird thing is that I can expose the property in my API through the include_columns parameter.

Patrick Yan
  • 2,338
  • 5
  • 25
  • 33
  • Can you post your address model, API definitions and the request you are trying to post? – Or Duan Jun 21 '14 at 10:40
  • @OrDuan - There is no address model. Those are just address columns on the user. The API definition is just a basic one. Request is just `first_name`, `last_name`, `email`, and `address` — I have tried with other random requests without address and without other fields. I cannot make a POST request with the address, but I can GET the address perfectly. – Patrick Yan Jun 22 '14 at 14:03
  • Sounds weird, Why you don't have the address in your include_colums? – Or Duan Jun 22 '14 at 14:25
  • @OrDuan - `include_columns` only affects GETs, not POSTs. I added `address` and the same error occurs with POST requests. – Patrick Yan Jun 22 '14 at 17:44
  • What's the version of your flask restless? becuase there is closed issue about that https://github.com/jfinkels/flask-restless/issues/135 – Or Duan Jun 22 '14 at 19:36

0 Answers0