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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gnucifer’s picture

Issue summary: View changes

Improvements

fago’s picture

Status: Active » Needs review
FileSize
1.08 KB

yes, 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.

Status: Needs review » Needs work

The last submitted patch, d7_restws_bundle.patch, failed testing.

klausi’s picture

Issue tags: +Needs tests

This is the perfect opportunity for a taxonomy term creation test case :)

klausi’s picture

Issue summary: View changes

Improvements

gnucifer’s picture

Issue summary: View changes

errors

nicxvan’s picture

This 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).

nicxvan’s picture

Priority: Normal » Major
nicxvan’s picture

Status: Needs work » Needs review
FileSize
984 bytes

I 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.

Status: Needs review » Needs work

The last submitted patch, 6: restws-correctedbundlekey-2090177-6.patch, failed testing.

gnucifer’s picture

I 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.

nicxvan’s picture

The tests fail because the tests are broken I believe, I do not know enough about tests to rewrite them though.

Kirschbaum’s picture

Looks 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.

Kirschbaum’s picture

Status: Needs work » Needs review
Kirschbaum’s picture

And here is a patch that includes CRUD tests for terms.

MaxMendez’s picture

Thanks Kirschbaum, your patch worked for me.

lokapujya’s picture

Status: Needs review » Reviewed & tested by the community

Fixes the issue and provides tests.

lokapujya’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs issue summary update

The issue summary needs to say what the solution ended up being.

RayCascella’s picture

Status: Needs work » Reviewed & tested by the community

This 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.