Steps to reproduce

1. Create new article and enter a tag in the 'Tags' autocomplete textfield, say 'Drupal' and save
2. Create another one and begin typing 'Drupal' again. Nothing will be returned.

Instead you'll see this error message in the database

Notice: Undefined index: vid in taxonomy_autocomplete() (line 95 of /Users/swentel/drupalcvs/drupal-head/modules/taxonomy/taxonomy.pages.inc).

When inspecting the $field variable, there is no 'vid' key in the 'allowed settings'.

Array ( [translatable] => 1 [entity_types] => Array ( ) [settings] => Array ( [allowed_values] => Array ( [0] => Array ( [vocabulary] => tags [parent] => 0 ) ) ) [storage] => Array ( [type] => field_sql_storage [settings] => Array ( ) [module] => field_sql_storage [active] => 1 [details] => Array ( [sql] => Array ( [FIELD_LOAD_CURRENT] => Array ( [field_data_field_tags] => Array ( [tid] => field_tags_tid ) ) [FIELD_LOAD_REVISION] => Array ( [field_revision_field_tags] => Array ( [tid] => field_tags_tid ) ) ) ) ) [foreign keys] => Array ( ) [indexes] => Array ( [tid] => Array ( [0] => tid ) ) [id] => 5 [field_name] => field_tags [type] => taxonomy_term_reference [module] => taxonomy [active] => 1 [locked] => 0 [cardinality] => 1 [deleted] => 0 [columns] => Array ( [tid] => Array ( [type] => int [unsigned] => 1 [not null] => ) ) [bundles] => Array ( [node] => Array ( [0] => article ) ) )


Array ( [vocabulary] => tags [parent] => 0 )

Even when deleting the term and create a new one, the same error occurs.

The patch attach fixes the issue, but I'm not sure if this needs to fixed here or in field API in taxonomy_field_settings_form where the 'machine_name' is used.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Anonymous’s picture

You're targeting the right area. Allowed values should be using machine names after #881530: Exportability of vocabularies is ruined by taxonomy field's 'allowed values' setting.

webchick’s picture

Issue tags: +Needs tests

No tests for autocomplete? tsk, tsk.

swentel’s picture

FileSize
3.88 KB

Added a simple test in TaxonomyTermTestCase at the bottom since that one is working with freetagging - didn't really see the need to create a new testcase because it's a small single test, unless you really want that.

flndr’s picture

I've tested the attached patch (not the simpletest one), now the ajax callback works as expected.

The autocomplete widget now displays the correct results. Although, when a term is selected, it replaces the name in the field with the tid. I suppose thats a different issue.

catch’s picture

flndr’s picture

I take back what I said about the selection not working. The above patch works as expected.

I'll make a patch with the above advice from catch in a minute.

Sivaji_Ganesh_Jojodae’s picture

+1 for #5.

Re-rolled patch #3 with taxonomy_vocabulary_get_names().

Sivaji_Ganesh_Jojodae’s picture

Status: Needs work » Needs review
flndr’s picture

Status: Needs review » Needs work
FileSize
909 bytes

This works for me...

Just started looking at D7 today, so... is there any reason that field_info_field can't return the vid along with the machine name for the vocabulary in the ['allowed values'] key? It looks like thats cached, and would avoid a bunch of queries on the database.

flndr’s picture

Status: Needs work » Needs review
catch’s picture

@justinzero: there's no place to put the vid information - this setting was originally changed in #881530: Exportability of vocabularies is ruined by taxonomy field's 'allowed values' setting for the exact reason of keeping the site-specific serial out of field configuration.

I don't think the extra query on the autocomplete path is going to make a huge amount of difference, if it did, we'd need to add caching for taxonomy_vocabulary_get_names().

flndr’s picture

Thanks for the info.

My patch should be disregarded over #7.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

RTBC for #7

netov’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
38.11 KB

When I try to use filter "Taxonomy: Term ID (with depth)" in Views with option "Autocomplete", I recieve an error.

Log:
PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'taxonomy_vocabulary JOIN tv td.vidtv.vid WHERE (td.name IN ('Дон')) AND (tv' at line 2: SELECT td.* FROM {taxonomy_term_data} td taxonomy_vocabulary JOIN {tv} td.vidtv.vid WHERE (td.name IN (:db_condition_placeholder_0)) AND (tv.machine_name = :db_condition_placeholder_1) ; Array ( [:db_condition_placeholder_0] => Дон [:db_condition_placeholder_1] => _ ) in views_handler_filter_term_node_tid->validate_term_strings() (line 290 of /var/www/bashnabash/sites/all/modules/views/modules/taxonomy/views_handler_filter_term_node_tid.inc).

Damien Tournoud’s picture

Status: Reviewed & tested by the community » Needs work

So, basically, #881530: Exportability of vocabularies is ruined by taxonomy field's 'allowed values' setting broke the autocomplete.

Sweet, that means we need tests.

catch’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: -Needs tests
FileSize
3.42 KB
2.62 KB

#7 has tests...

To avoid any more confusion, let's re-upload the patch, also attaching one with just the tests to confirm they actually catch the bug.

@netov: I haven't looked at the views code, but there's two possibilities:

1. the patch here fixes it - please try with it applied.
2. #881530 broke views - in which case this is going to need a companion issue in the views queue, and I'll be further annoyed that it got in without the API change being discussed.

swentel’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

There are tests in 5 and 7

The views autocomplete is probably related in views itself ...

swentel’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

Aargh, sorry cross post :(

Damien Tournoud’s picture

I was actually looking at #9. Sorry for the confusion.

catch’s picture

Priority: Major » Critical

Tagging being broken is critical.

catch’s picture

grr, my vim config is trimming whitespace for some reason, need to fix that.

Status: Needs review » Needs work

The last submitted patch, 936836_autocomplete_term_7.patch, failed testing.

catch’s picture

Status: Needs work » Needs review
FileSize
3.42 KB

sorry, wtf.

chx’s picture

Status: Needs review » Reviewed & tested by the community

Looks good. taxonomy_vocabulary_get_names is not horribly expensive at all.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed to HEAD. Thanks folks!

netov’s picture

Patch of course was done:))

Dave Reid’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.