jfinkels / flask-restless

NO LONGER MAINTAINED - A Flask extension for creating simple ReSTful JSON APIs from SQLAlchemy models.
https://flask-restless.readthedocs.io
GNU Affero General Public License v3.0
1.02k stars 301 forks source link

the 'type' field name may conflict with SA #624

Closed tarekziade closed 7 years ago

tarekziade commented 7 years ago

Reading the code at https://github.com/jfinkels/flask-restless/blob/master/flask_restless/views/resources.py#L689

This assumes a SA mapping does not have a column named 'type' which I think it's possible. That would mean it would be impossible to update that field via a PATCH call.

Wouldn't it be safe to use a custom prefix to avoid name conflicts ? or move out of the 'data' mapping when the client sends data

jfinkels commented 7 years ago

JSON API deals with this by requiring the following JSON representation of a resource:

{
  "data": {
    "id": 123,
    "type": "foo",
    "attributes": {
      "type": "whatever"
    }
  }
}

That is, a column named "type" would be represented as a "type" element under the "attributes" element in the JSON representation.

tarekziade commented 7 years ago

sorry I missed the attributes level. Thanks for the answer