oeplatform icon indicating copy to clipboard operation
oeplatform copied to clipboard

Id not returned after successfull insert

Open henhuy opened this issue 5 years ago • 5 comments

When running insert command from here: https://oep-data-interface.readthedocs.io/en/latest/api/how_to.html#insert-data data gets inserted and I get Response Code 201 But I cannot find resulting ID in response? results.json() returns {'description': [['id', 20, None, 8, None, None, None]], 'rowcount': 1} but no key data, as shown in example:

>>> import requests
>>> data = {"query": {"name": "John Doe"}}
>>> result = requests.post(oep_url+'/api/v0/schema/sandbox/tables/example_table/rows/new', json=data, headers={'Authorization': 'Token %s'%your_token} )
>>> result.status_code
201
>>> json_result = result.json()
>>> json_result['data'] # Show the id of the new row
[[1]]

henhuy avatar Sep 25 '20 13:09 henhuy

Just saw this issue.

This is where the response is built up, and yes, the ID is not part of it:

https://github.com/OpenEnergyPlatform/oeplatform/blob/45f31b1ed495026be7a9242307214a956a7174c2/api/actions.py#L1401-L1414

I think this would be good to have? But I'm a bit afraid that this is a big change to the API? What do you think about this?

jh-RLI avatar Mar 21 '24 17:03 jh-RLI

In the example, there is a key data which is not present yet in the response. IMO adding an entry data holding the resulting ID, would only add value and cannot break anything.

henhuy avatar Mar 22 '24 07:03 henhuy

Right, I wonder where that key came from :D It probably got kicked out accidentally (or on purpose - without documentation of course). I will discuss this in the next OEP-DEV round. I vote for implementing it.

jh-RLI avatar Mar 25 '24 12:03 jh-RLI

  • I don't even know why the returned description is for the id column. it's not intuitive at all and maybe should be removed completely.
  • as for returning the row id: I think it's a good idea. It just gets a little more complicated. the api also allows to insert multiple values at once. should the return value then be an array of the ids?

wingechr avatar Apr 12 '24 09:04 wingechr

Good point. I think at some point we shoud create a v1 of the API and streamline things like this.

I would assume that in this case an array with all new IDs is returned. But I'm not as familiar with how other apis do this either. Maybe I can find a "best practice", otherwise we can decide here what we want and then just document that decision.

BTW: I added this not "yet very helpful" open api documentation to our oeplatform docs. So we could just start updating the documentation and show it there. Currently, to show changes in the documentation, you have to manually generate the open api schema.

https://openenergyplatform.github.io/oeplatform/install-and-documentation/oeplatform-code/web-api/oedb-rest-api/#open-api

jh-RLI avatar Apr 12 '24 12:04 jh-RLI