Closed tmst closed 7 years ago
@tmst Do you have a bare-bones sample app I could run while digging into this?
I'm not sure how to run the test suite for the EPD examples. But the "keys_with_ancestors" example seems to display this problem:
myparent1
mymodel1
:+1: Thanks i'll look into it
@tmst That example app does as you mentioned:
$ curl http://localhost:8080/_ah/api/myapi/v1/mymodels/myparent2
{
"error": {
"code": 404,
"errors": [
{
"domain": "global",
"message": "Parent myparent2 does not exist.",
"reason": "notFound"
}
],
"message": "Parent myparent2 does not exist."
}
}
However, the 404 is not from the library, but rather from the "user code" of the app.
Right. I touched upon this fact in my original question. The trouble is that, due to the design of EPD AliasProperty, it seems unavoidable that the application code be written in this manner. Specifically, that the existence of a parent entity be verified in every HTTP method operation on a child Kind, regardless of whether a new child entity is being added to the datastore, or the child entities are simply being listed.
I suppose it's sort of nit-picky issue. In most use cases the parent will be populated in the request from a list of parents on the client, and if a nonexistent parent is sent in the query then another problem also exists.
Yeah the parent/child thing is not a builtin part of the library, was just my imagination for something you might build on top of it.
Thanks. I'm fine with this issue being closed. StackOverflow is probably a better place to find out how a query might be written along the lines of the "keys_with_ancestors" example but in which the existence of parents is not verified.
Sorry I couldn't do more. Cheers. (Again, thanks for taking the time to engage.)
If MyModel has AliasProperty
attr_id
, a query filter which specifies a value forattr1_id
will fail if no correspondingAttr
entity exists in the datastore (attr
is a KeyProperty):The query should correctly return an empty list as it does with any other property filter having no matches.
BTW, I observe this behavior in API Explorer. I'm not certain that it's something that can't be handled on the application side in the method
AttrIdSet
with the following signature:The problem, of course, is that this method gets invoked for all HTTP methods, not just queries. When inserting or deleting an entity it must be verified that the entity exists, whereas with queries, we're only interested in whether a MyModel instance exists having an
attr_id
== 'attr1'`.