First off, thanks for a great module. It has saved me in some recent projects where the Services module proved non viable or at least very cumbersome to use. Now I seem to have run into a bug. Creating taxonomy terms through POST does not seem to be working. It's strange that no one else has run into this since it should be a pretty common task, but I could not found any other issues.
First off, I'm not quite sure how to find out the correct format to post in.
But "vocabulary" and "name" are the only required properties in entity/modules/taxonomy.info.inc so I figured I needed at least those.
With this object:
{
name : "taxonomy term name"
vocabulary : "123"
}
I get:
406 Not Acceptable: Missing bundle: machine_name
machine_name is not listed as a property in entity/modules/taxonomy.info.inc though, so if I add it I instead get:
406 Not Acceptable: Unknown data property machine_name
If I remove the bundle check, the term is saved correctly.
In the documentation for hook_entity_info (http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_entity_info/7) "bundle keys" are described as:
bundle keys: An array describing how the Field API can extract the information it needs from the bundle objects for this type. This entry is required if the 'path' provided in the 'bundles'/'admin' section identifies the bundle using a named menu placeholder whose loader callback returns an object (e.g., $vocabulary for taxonomy terms, or $node_type for nodes). If the path does not include the bundle, or the bundle is just a string rather than an automatically loaded object, then this can be omitted. Elements:
bundle: The name of the property of the bundle object that contains the name of the bundle object.
So $entity_info['bundle keys']['bundle'] should not be expected to be found on the $term object itself, but is only metadata from extracting the correct value from the vocabulary object?
Because of my limited knowledge of the inner workings of EntityAPI I not sure how solve this issue the "right" way. But it seems to me that one either have to drop the check, or fix the validation. If there is a bundle check that would be a little bit weird for taxonomy terms though, for only vid and name are actually required in taxonomy_term_save, and vid is not the actual bundle property.
Comment | File | Size | Author |
---|---|---|---|
#12 | restws-bundleKeyTerms-2090177-12.patch | 4.72 KB | Kirschbaum |
#10 | restws-bundleKeyTerms-2090177-10.patch | 1.37 KB | Kirschbaum |
#6 | restws-correctedbundlekey-2090177-6.patch | 984 bytes | nicxvan |
#1 | d7_restws_bundle.patch | 1.08 KB | fago |
Comments
Comment #0.0
gnucifer CreditAttribution: gnucifer commentedImprovements
Comment #1
fagoyes, I ran over an old commit which I forgot to push back then. I ran into the same issue and the attached patched fixed it for me.
Comment #3
klausiThis is the perfect opportunity for a taxonomy term creation test case :)
Comment #3.0
klausiImprovements
Comment #3.1
gnucifer CreditAttribution: gnucifer commentederrors
Comment #4
nicxvan CreditAttribution: nicxvan commentedThis still is not working. I have applied the patch and while the erroneous 406 error disappeared the taxonomy still is not created.
My tax array looks like this:
// Build Taxonomy array
$taxonomy_info = array(
'name' => $taxonomy_name,
'vocabulary' => get_vid($taxonomy_vocabulary)
);
Json that is posted looks like this:
{"name":"New1Manufacturer","vocabulary":"2"}
I get a 500 error in the response and the following in the logs:
Notice: Undefined variable: wrapper in RestWSEntityResourceController->create() (line 162 of httpdocs/sites/all/modules/restws/restws.entity.inc).
Comment #5
nicxvan CreditAttribution: nicxvan commentedComment #6
nicxvan CreditAttribution: nicxvan commentedI was able to correct the incorrect wrapper variable with the help of stephenacrossri
I've tested and been able to create a taxonomy term with this patch.
Comment #8
gnucifer CreditAttribution: gnucifer commentedI ran into this again after updating restws (and having assumed this was committed). Works after applying patch in #6. Odd that so many tests fail because of this, because of time constraints I don't have time to look into why. I understand how cumbersome this kind of work is for maintainers, so I just hope that someone can have look at this.
Comment #9
nicxvan CreditAttribution: nicxvan commentedThe tests fail because the tests are broken I believe, I do not know enough about tests to rewrite them though.
Comment #10
Kirschbaum CreditAttribution: Kirschbaum commentedLooks like patch #6 erroneously removes:
$entity_info = entity_get_info($this->entityType);
Even with that fixed, however, checking $entity_info['entity keys']['bundle'] to see if it's empty no longer seems to work because that value is not empty for terms (as of today with stock Drupal 7).
The patch in #1 actually worked like a charm for me. I just needed to move it around and refactor a bit as it tries to use the $wrapper object before it was available. Updated patch attached.
Comment #11
Kirschbaum CreditAttribution: Kirschbaum commentedComment #12
Kirschbaum CreditAttribution: Kirschbaum commentedAnd here is a patch that includes CRUD tests for terms.
Comment #13
MaxMendez CreditAttribution: MaxMendez commentedThanks Kirschbaum, your patch worked for me.
Comment #14
lokapujyaFixes the issue and provides tests.
Comment #15
lokapujyaThe issue summary needs to say what the solution ended up being.
Comment #16
RayCascellaThis issue is still happening in 7.x-2.8. The patch in #12 still applies, and appears to resolve this specific issue, as I no longer see the "missing bundle"/"unknown property" errors. I'm working on sending og_membership data and see it hit the creation calls for that entity, with new errors, which I believe are more OG related than REST. Considering the patch is still applicable and effective, I'm setting this to RTBC.