Problem/Motivation
If a user attempts to set a default value on taxonomy autocomplete widget for a term that does not yet exist, the term is not autocreated as expected. The user has no indication that the term was not created. Furthermore, for fields other than the core Tags field, the failure to autocreate the term breaks new submissions entirely.
Steps to reproduce
- On a fresh standard install of D7 or D8, create a new vocabulary named Test. Do not create any terms.
- Go to
admin/structure/types/manage/page/fields. - Add a new field:
- Label: Test
- Name:
field_test - Field type: Term reference
- Widget: Autocomplete term widget (tagging)
- Select the Test vocabulary as the vocabulary for the field when prompted.
- In the default value field of the widget configuration form, enter a new term Foo.
- Save the form.
- Now, go to
node/add/page. Note that no default value is set in the Test field. - Enter a title. Leave the Test field blank.
- Save the node.
Expected result
The node is saved with a title and no tags.
Actual result
You receive error:
PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'autocreate' for column 'tid' at row 1: INSERT INTO {taxonomy_index} (nid, tid, sticky, created) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array ( [:db_insert_placeholder_0] => 1 [:db_insert_placeholder_1] => autocreate [:db_insert_placeholder_2] => 0 [:db_insert_placeholder_3] => 1312137784 ) in taxonomy_field_insert() (line 1701 of /.../modules/taxonomy/taxonomy.module).
Note: This does not seem to be reproducible using the core Tags vocabulary. In that situation, it is a usability issue, because the user sets a default value on the field, but no default value is saved or used. Nodes can still be created in that case.
Proposed resolution
The current patch uses two steps to resolve the issue:
- Make taxonomy_field_widget_form() handle the case where $item['tid'] == 'autocreate' so that everything is passed through correctly until taxonomy_field_presave() transforms the autocreate value into a real tid.
Remaining tasks
None.
Done
- The problem does not exist in D8. So this is a D7-only issue.
- The patch has been reviewed by at least 4 people.
- Automated tests are provided.
User interface changes
None.
API changes
None.
Original report by @dynamicdan
The following error started appearing when saving a NEW content item:
PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'autocreate' for column 'tid' at row 1: INSERT INTO {taxonomy_index} (nid, tid, sticky, created) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array ( [:db_insert_placeholder_0] => 40 [:db_insert_placeholder_1] => autocreate [:db_insert_placeholder_2] => 0 [:db_insert_placeholder_3] => 1303921062 ) in taxonomy_field_insert() (line 1673 of /.../modules/taxonomy/taxonomy.module).
This was after installing a whole bunch of standard taxonomy modules (Taxonomy Manager, pathauto, Taxonomy CSV, Taxonomy menu etc.). Disabling them did not resolve the problem. Through testing, it appears that submitting a custom content type with no entry in the default taxonomy term field (using the autocomplete or any other widget) triggers the error.
I can't confirm if the client is sending an empty/null term or the server is making stuff up.
I have 3 taxonomy term references, but only the first is causing issues. Setting the term to none for the other 2 (using the select widget) works fine. It's just when not entering text for the first taxonomy autocomplete field that an error is triggered.
BTW, this bug hurts... BAD. Only temporary work around would be to ensure a tag is always entered.
Further research from this:
"taxonomy form validation creates new terms" (http://drupal.org/node/826028 or #826028)
and (http://druplicon.info/bot/log/drupal-support/2011-02-28):
Hi, im having issues implementing a custom entity in d7. i've implemented the entity but when i attempt to save an entity that has a taxonomy field, i get the error msg "366 Incorrect integer value: 'autocreate' for column 'field_taxonomy_tags_tid' at row 1"
Suggestions:
reading incorrect fields from form post?
widget malfunctioning?
default vocab giving me probs?
| Comment | File | Size | Author |
|---|---|---|---|
| #114 | 1140188-taxonomy-autocreate-incorrect-integer-114.patch | 5.22 KB | torotil |
| #102 | 1140188-102.patch | 2.83 KB | jhedstrom |
| #102 | 1140188-102-TEST-ONLY.patch | 1.82 KB | jhedstrom |
Comments
Comment #1
catchThis will need to be fixed in 8.x first and backported (there's no code changes in taxonomy module yet so it should be the same patch).
Can you reproduce this on a clean Drupal 7 install?
Comment #2
dynamicdan commentedI'm not to keen to install a new version and redo everything I did prior to the bug... I have no idea when it stopped working as the problem is only related to adding or not adding tags for a given taxonomy reference and a given content type.
I have been able to find out more info... The taxonomy module is attempting to create a tag named 'untagged' which is failing. It's obvious to me that the tid value of 'autocreate' should be replaced or simply removed from the query so that the MYSQL auto_increment feature is used (considering it's a new tag).
Below are the 3 taxonomy fields (tags, t_t = theme_tags and regions).
It seems clear that the vocabulary_machine_name 'tags' handles things differently from the other 2 taxonomy fields/inputs.
I've debugged further the value of $instance from the function: taxonomy_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items)
Seems like this taxonomy has a default_value ?? I can't for the life of me find out where 'untagged' comes from (which php file or DB field).
Any one know why drupal is trying to set a default value?
Comment #3
catchIt looks like one of the contrib modules you installed may have altered the field/instance definition - and to an invalid setting. This would explain why you are still getting the error after disabling those modules - they'd have to explicitly remove that change again.
I'm downgrading to 'major' and 'needs more info' - we'd need to find out which module is setting this, which means grepping the folders of the modules you mentioned in the opening post for 'untagged' - then we can move the bug report to that module.
Comment #4
dynamicdan commentedI have tried grepping for 'untagged' (grep -R "untagged" *) with no success.. Could this be in a language file somewhere (like $tag_default = EN_UN.'tagged')? I aslo checked the database content but with no luck.
Setting a default tag for the field changed 'untagged' to my 'not tagged' phrase but I still have the same bug.
I'm more interested in this function below which is meant to replace the 'autocreate' tid with an actual id as I understand it.
(I have no clue what the event flow is in this drupal world... _presave called before db_insert() or execute() and/or after taxonomy_term_save() ?)
With my current testing, it seems like the if statement doesn't get triggered.
BTW, auto_increment is not enabled on tid, so no quick fix for me... perhaps I should add the auto_increment setting and remove the tid insertion part of the query... or hijack the spot where it adds this 'autocreate' term construct.... = bad hacks.
Should we change the title to:
"saving tags with tid as 'autocreate' fails when no tags are entered by the user"
?
Comment #5
dynamicdan commentedChanged status so that ppl know to reply.
Comment #6
dynamicdan commentedComment #7
dynamicdan commentedFound out via IRC that ppl are ignoring this because it's marked as 8.x and not 7.x
Changing to 7.0-rc4 because that's where users currently notice the problem (regardless of if it's drupal core or not).
Comment #8
catchNo patches are getting into 7.x that haven't been committed to 8.x first. Right now the rate of commits to D8 is ridiculously slow, but changing version to D7 only decreases further the chance of this being looked at and eventually fixed.
Comment #9
dynamicdan commentedWithout doing a full install and retest of all the modules that may have caused the problem, I have noticed something useful.
I believe the problem doesn't exist when adding new content via the frontend edit/add mode. When I was editing as an admin from the admin interface, the error was showing.
I have also disabled taxonomy_menu (the think that generates a block from a list of taxonomy terms automatically). I noticed some errors in that module showing up on the admin screen. I will monitor the problem as our site develops and migrates to a production environment.
Comment #10
dynamicdan commentedOk, still have the problem when the user doesn't enter any tags for a node.
I believe this is NOT due to 3rd party modules. My only option atm is to hack/hook into the taxonomy 'get args' function and set 'not tagged' as a valid existing tag instead of relying on the 'autocreate' default 'untagged' stuff. Otherwise, I could hook into the submit function with JS and set a value if applicable on submit.
I still don't know where the value from 'autocreate' comes from. I'm starting to think the problem lies with the database default values for a taxonomy or the autocomplete widget.
Comment #11
sunOnly one person is able to reproduce this bug, demoting to normal.
Given the comment in #9, #996240: Javascript error in node preview when there are unlimited value fields in overlay might be related.
Comment #12
altaso commentedI have the same error:
PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'autocreate' for column 'tid' at row 1: INSERT INTO {taxonomy_index} (nid, tid, sticky, created) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array ( [:db_insert_placeholder_0] => 181 [:db_insert_placeholder_1] => autocreate [:db_insert_placeholder_2] => 0 [:db_insert_placeholder_3] => 1309204315 ) in taxonomy_field_insert() (line 1673 of /DEVEL/alpinecanada/modules/taxonomy/taxonomy.module).
Drupal 7.0
Install profile Acquia Drupal (acquia-7.x-1.1)
Taxonomy 7.0
I'll see if I can get more info, but for now I think I'm going to make taxonomies required so users would not try submit empty fields.
Note: It looks like this is happening only when trying to crate new node ... when editing existing node and taxonomy tags auto-complete field is empty everything seems to be working fine.
Comment #13
dsdart commentedNot sure if this will help with debugging, but when I deleted the taxonomy term field from my content type, and re-added it, the problem went away. (I don't have a lot of content, so I could manually add back the tags)
Comment #14
dynamicdan commentedError only on new node might be the key here. I haven't experienced this problem lately, but I know it's still there.
I would suggest testing in that direction. Could be linked with the node not existing when a new tag needs to be added.
Comment #15
juahoo commentedI'm getting this error as well and have been unable to resolve it.
PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'autocreate' for column 'tid' at row 1: INSERT INTO {taxonomy_index} (nid, tid, sticky, created) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array ( [:db_insert_placeholder_0] => 14 [:db_insert_placeholder_1] => autocreate [:db_insert_placeholder_2] => 0 [:db_insert_placeholder_3] => 1311777059 ) in taxonomy_field_insert() (line 1701 of /modules/taxonomy/taxonomy.module).I've tried deleting and re-adding several fields in my content type, but it hasn't worked so far.
Drupal 7.4
Install Profile Minimal (minimal-7.4)
Taxonomy 7.4
PHP 5.2.17
MySQL 5.0.91-log
Host: 1&1 shared server
Comment #16
xjmI ran into this same issue today.
Steps to reproduce
admin/structure/types/manage/page/fields.field_testnode/add/page.Expected result
The node is saved with a title and no tags.
Actual result
You receive error:
Note: This does not seem to be reproducible using the core Tags vocabulary. In that situation, it is a usability issue, because the user sets a default value on the field, but no default value is saved or used. Nodes can still be created in that case.
Comment #17
xjmAdded summary with the above steps to reproduce.
Comment #17.0
xjmUpdated issue summary.
Comment #17.1
xjmClarification: The field is empty when the form is loaded.
Comment #18
xjmComment #19
agi.novanta commentedI investigated the issue. The issue seems to be related with the merging with default value. The presave callback is currently called before merging the data with default value so the callback is not applied to the data added automatically.
taxonomy module use uid = 'automatic' for those tags which are not added yet and it actually fills in
taxonomy_field_presave(), if the tag is added by default the function is not called and we turn in this issue.My little patch simply put
_field_invoke_default('insert', $entity_type, $entity);, which load default data, infield_attach_presave()before calling the actual presave. This patch, however, should break those modules which rely on this order.Comment #20
xjmComment #22
agi.novanta commentedI think this time i have got the problem.
taxonomy_field_widget_form()add tags to form with this:but if
$itemcome from default,$item['taxonomy_term']is not set and$item['tid'] = 'autocreate', so we need to cast$itemas an object like this:taxonomy_field_insert(), again, the$itemwhich comes from default has$item['tid'] = 'autocreate'even if that tag is already on database so we need to check like:and if the tag is not on database we need to insert it, so i moved insert code in a function:
Here comes the patch.
Comment #23
marblegravy commentedInstalled the patch at #22 on a website exhibiting all of the symptoms listed here and everything now works.
Brilliant!
Comment #24
xjmThanks for the patch! Here are a few pointers for code cleanup:
I'd suggest a comment explaining these two lines. Edit: Let's expand this into a full if/else.
Lost a final comma here. Let's not make this change; the final comma should be included in arrays according to the coding standards.
Do we need to create this function? The logic is simple enough that it could be simply included in hook_field_insert(), and I don't see a strong case for reusing it.
I'd change this comment to: "Try to match autocreated terms to existing terms of the same name in the database." The comment needs capitalization and a period.
Replace this with the foreach loop from the function.
I'd add a line of whitespace above and below this hunk. Additionally, let's change the comment to: "Save any new terms that were not matched."
Finally, there's several places in the patch that have trailing whitespace. Let's make sure to get rid of that when we reroll it.
11 days to next Drupal core point release.
Comment #25
xjmProbably should add a test for this as well.
Comment #25.0
xjmGeneralized file path in error.
Comment #25.1
xjmUpdated issue summary.
Comment #26
xjmIs it possible to instead save the term when we save the field instance itself, rather than passing around autocreate forever as the tid for terms that may or may not exist?
Comment #26.0
xjmUpdated issue summary.
Comment #27
lnunesbrI have reviewed those points, and have applied xjm suggestions according the coding standards...
follows a patch...
actually i'm not very familiar with simpletests...
Comment #28
lnunesbrchanging the status
Comment #29
Anonymous (not verified) commentedThe patch from #27 worked.
Except I didn't even have a Default value! I just left the field empty (not required). Without the patch I could not save a node on D7.
Please backport to D7, this is very needed :)
Comment #30
sunThe patch needs work. I'll let someone else point out the details.
Comment #31
ericduran commentedThe white spaces needs to be cleaned out.
I didn't actual review the code, it just stood out right away.
15 days to next Drupal core point release.
Comment #32
pwolanin commentedJust ran into this - though it seemed like part of the problem was setting a fixed number of allowed values, rather than unlimited.
Comment #33
xjmWe might want to change the approach a bit, but at a minimum it needs some coding standards cleanup. Tagging as novice to reroll according to coding standards. References: http://drupal.org/coding-standards and http://drupal.org/node/1354
The patch in #27 needs to have trailing whitespace removed and a newline added at the end of the file. Additional comments:
Needs a space after //, a period, and should start with "Assign" rather than "Assigning." Also, the comment itself is a bit vague and unclear.
Let's simplify to if/elseif/else here.
Again, this comma should not be removed.
Should start with "Creates." Also, I'd suggest something a bit clearer, like: "Creates new term from autocomplete field values." Also, we need the @param and @return values.
I'd remove this comment.
I'd change this to: "Set tids for existing terms."
Why $existing[1]? At a minimum, this needs a comment. Better, we should use something more meaningful than the numeric index for better readability.
Needs a space after //, a period, and should start with "Assign..." I'd also suggest more specific comments explaining each case.
We could probably simplify this to if/elseif/else.
Again, this is not a good change. Let's keep that comma.
We also still need a test, which is another task someone could do.
Comment #34
kathyh commentedPatches to address #33. Still not sure on why existing[1] was used - maybe someone can comment on that. In the meantime, set the 1 to $termname=1;
After botcheck - this issue still needs:
-review approach
-write a test
Comment #35
xjmThanks for the reroll and cleanup; it's easier to look closely at the code in a clean patch.
Mmm, I think this just hides that it's using magic numbers, so let's not do that.
Comment #36
xjmRegarding the general approach: I really think we should not save 'autocreate' as the default field value. I'm more convinced of this now than I was in August for a few reasons. One, we're adding lots of queries to look up what that term should be--lots--and secondly, we're lying to other modules that handle these form values and telling them we've got an autocreated term in the set.
The correct approach is to save the default value term before saving its value to the field settings.
Comment #37
xjmOh, another thing: Two people have now mentioned that they encountered this problem but it didn't seem to necessarily be tied to a default value. Can we get steps to reproduce for those cases as well to be sure we cover them?
Comment #38
xjmThe current novice task in this issue is to create a functional automated test that fails without the patch and passes with it, using the steps to reproduce from the summary. Thanks!
I'd also like to see the point in #35 fixed if we do consider the current approach, but I'd prefer a different one.
Comment #39
cameron tod commentedI've written a test case that is hopefully useful. Here it is: https://github.com/cam8001/Drupal-test-cases
I couldn't get the patch to apply to the D8 trunk as it is now, I might attempt a reroll tomorrow if no one has beaten me to it.
Comment #40
cameron tod commentedOn the ride to work I realised this would be much more useful as a patch to taxonomy.test. Here it is :)
Comment #41
xjmYay! Setting NR for testbot; we are expecting a failure.
Comment #43
xjmExcellent. This will make writing a better fix much more efficient. Thanks cam8001!
Here are some points for code style cleanup:
This class needs a docblock. Also "TaxonomyBugTestCase" is not the most descriptive.
We omit docblocks for getInfo(), setUp(), and tearDown(). (There's an existing issue debating this somewhere, but for now we should continue to, for consistency. Also there isn't actually an interface to implement.)
We don't need to link the issue in the codebase, because people will be able to look it up with git blame once the patch goes in. :) Also, the description is a bit long. But actually, now that I think about it, I think we can probably put the test method inside an existing class somewhere instead. So ignore these first three points and instead look for a different class where it makes sense to add this test method?
Let's remove these comments.
This should start with a third person verb, something like, "Tests autocreation of default value terms." or something. Reference: http://drupal.org/node/1354#functions
It's preferred not to use t() on the assertion message texts (the last argument), because no translator is going to translate them. (The first args do still need t().)
These two comments need periods and articles (a, the, etc.) I'd suggest:
Assign the field to the vocabulary.and
Set a non-existent default value for the field.Rather than defining the $label variable, can we just put this in the array definition for better readability?
I think we can just remove the words "Code taken from" here?
We need a single newline at the end of the file here.
So it would be good to get a reroll that fixes these things. Thanks!
Comment #44
cameron tod commentedWow what a thorough review, I'll tidy things up per your specs a bit later on tonight!
Regarding the $label definition, I've assigned it to a variable as it is checked in an assertion later on. I think it's the best way to assure that the value in the assertion matches the value assigned. It does look a bit ugly though. What do you think?
Comment #45
xjmAh, I missed that
$labelwas used later on. That's fine then, so disregard that point. :)Comment #46
cameron tod commentedOK, so I:
The test creates and logs in a new user, overriding the previous tests' user setup. This means that for the test needs to be the last function defined in the class, or it may jeopardise the integrity of other tests that run as a user with different permissions. The user has the same permissions as the one used in TaxonomyTermTestCase, but as its a field widget test, I decided to put it into TaxonomyTermFieldTestCase.::setUp() is called on every test* method call, so this point is wrong.
The final check only asserts for creation of the node, it doesn't check that the taxonomy term was created successfully. But, it should fail without the patch in this issue, and pass with it.
Setting issue to needs review, expecting fail.
Comment #48
cameron tod commentedI will test the patch against the new test case this week.
Comment #49
xjmExcellent; this looks much better. Just a couple remaining code style nitpicks:
Lots of trailing whitespace. I suggest configuring your editor to display this if possible. (I know I have a habit of hitting tab to indent on every line, which leads to this sometimes. Some editors also just add it automatically.)
"Tests" rather than "test". (Reference: http://drupal.org/node/1354#functions)
Thanks!
Comment #50
NROTC_Webmaster commentedHere is the test only updated per #49. The code since the patch in #34 has changed significantly so I'm not sure how that should be handled.
Comment #52
xjmThanks @NROTC_Webmaster; those changes look good.
Just noticed these use
assertRaw()to match strings int(), with placeholders and everything, which seems kind of weird. Shouldn't it beassertText()? Or am I mistaken?Comment #53
NROTC_Webmaster commentedxjm,
I'm really not sure the proper way to do this. I'm going to assume you are correct and change assertRaw() to assertText(). Let me know if it needs any other changes.
Comment #55
xjmWell, the test failures are different, which probably means I was wrong. :) I'll try running the test locally.
Comment #56
NROTC_Webmaster commentedI'm not sure what has changed but now every part of the test is failing. Anyways here are the latest for the test and original patch. If anyone has any ideas please let me know.
Comment #58
berdirThe autocreate behavior has been changed with the introduction of the TaxonomyTerm entity class.
Can you verify if this bug still occurs?
Comment #59
catchComment #60
boztek commentedTested this issue on D7 and D8 with MySQL and sqlite
Drupal 7 (MySQL)
PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'autocreate' for column 'field_test_tid' at row 1: INSERT INTO {field_data_field_test} (entity_type, entity_id, revision_id, bundle, delta, language, field_test_tid) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6); Array ( [:db_insert_placeholder_0] => node [:db_insert_placeholder_1] => 1 [:db_insert_placeholder_2] => 1 [:db_insert_placeholder_3] => page [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => autocreate ) in field_sql_storage_field_storage_write() (line 448 of .../drupal/modules/field/modules/field_sql_storage/field_sql_storage.module).Drupal 7 (sqlite)
Notice: Undefined index: name in taxonomy_field_formatter_view() (line 1484 of .../drupal/modules/taxonomy/taxonomy.module).Drupal 8 (MySQL)
PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'autocreate' for column 'field_test_tid' at row 1: INSERT INTO {field_data_field_test} (entity_type, entity_id, revision_id, bundle, delta, langcode, field_test_tid) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6); Array ( [:db_insert_placeholder_0] => node [:db_insert_placeholder_1] => 1 [:db_insert_placeholder_2] => 1 [:db_insert_placeholder_3] => page [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => autocreate ) in field_sql_storage_field_storage_write() (line 452 of .../drupal/core/modules/field/modules/field_sql_storage/field_sql_storage.module).Drupal 8 (sqlite)
Notice: Undefined index: name in taxonomy_field_formatter_view() (line 1236 of .../drupal/core/modules/taxonomy/taxonomy.module).Comment #61
boztek commentedComment #62
andypostseems related or duplicate #873722: 'autocreate' == 0
Comment #63
xjmI don't believe it's a duplicate, though in both cases our "magic" value name is being treated as an integer.
Comment #64
alan d. commentedWhat is this code for?
The formatting is wrong on this
#1377628: taxonomy_get_term_by_name() should be taxonomy_term_load_multiple_by_name(), you need to use taxonomy_term_load_multiple_by_name().
This returns an array of terms indexed by tid.
The first term is usually referenced similar to:
So do you mean this? I'm really not sure...
Comment #65
mitron commentedRepeated steps to reproduce on Drupal 8 and received expected result.
Steps
Label: Test
Name: field_test
Field type: Term reference
Widget: Autocomplete term widget (tagging)
Result
The node is saved with a title and no tags.
Comment #66
xjmYeah, this is still broken.
Comment #67
torotil commentedI investigated the problem again for D7 and came up with a slightly smaller patch.
I've also learned quite a few things about the field api during that:
Comment #68
jibranSending for test.
Comment #70
torotil commentedThe patch is for 7.x - naturally it fails to apply in 8.x!
Comment #71
torotil commentedI've just tested this with D8:
In D8 "autocreate" is not used anymore so this bug report is not applicable to D8 anymore. Marking this as 7.x-dev and requeueing for automated tests.
Comment #72
torotil commented#67: taxonomy_default_value_autocreate.patch queued for re-testing.
Comment #74
torotil commentedHere's another try to get this patched.
Comment #75
thelee commentedi can second that i've run into this exact issue (and been doing the temporary work around of just making tags a required field).
would be nice to get some vague movement on the latest patch from someone more knowledgeable than i.
Comment #76
maartendeblock commentedI can confirm the above patch #74 works. I have had this problem with 2 commerce websites. This really should be fixed asap.
Comment #77
cameron tod commentedThe patch in #74 seems to work fine here too, nice fix! We can't put it in without tests though.
Quick review:
Can we comment what $autocreates is doing here?
It would be great to comment these cases too - although I recognise they were not commented previously.
Comment #77.0
cameron tod commentedUpdated issue summary.
Comment #78
ianthomas_ukWhile it's useful to have a working patch for 7.x, it won't be committed unless the issue has already been fixed in 8.x. I also don't think this qualifies as critical, and has previously been downgraded to major by a core committer.
Comment #79
berdirThe bug no longer occurs in 8.x, according to #71. So the only thing that would be necessary there is test coverage, if we don't have it already.
Comment #80
torotil commentedThis is D7 only. This bug does not exist in D8.
Here is a patch containing tests. This will fail (without the fixes).
Comment #81
torotil commentedForgot to attach the patch ;)
Comment #83
torotil commentedThis patch has the tests as well as the fix.
Comment #84
torotil commentedComment #86
nmeegama commented#83 patch is for Drupal 7
Comment #87
dieuwePatch in #83 worked for me.
Comment #89
Marvine commented#83 works for me to (it was an error with default tag taxonomy vocabulary).
Comment #91
torotil commentedI've added a comment above to explain the 'autocreate'-special-case as requested in comment #77.
I'm also adapting the the issue summary and set it to RTBC as per #76, #86, #89.
Comment #94
David_Rothstein commentedTestbot fluke.
Comment #97
torotil commentedAgain RTBC as it was before the testbot fluke.
Comment #98
David_Rothstein commentedI tried to reproduce this in Drupal 8 and while it probably doesn't have the exact same bug, you can never actually get far enough to test it due to a very similar bug that kicks in slightly earlier. From a fresh installation of Drupal 8:
1. Add a taxonomy term entityreference field to the basic page content type.
2. Configure it to be unlimited and to point to the "Tags" vocabulary and to have the "Create referenced entities if they don't already exist" checkbox checked. (Don't try to add any default values yet, since it won't let you until that checkbox is checked and saved.) Save the form.
3. Now go to Manage Form Display and configure the field to be "Autocomplete (Tags Style)".
4. Now go back to edit the field and in the default value section enter a new term "Foo".
5. When you save you get this:
Fatal error: Call to a member function uuid() on a non-object in .../core/lib/Drupal/Core/Field/EntityReferenceFieldItemList.php on line 115Although the cause is presumably different in Drupal 8 than Drupal 7, the symptoms are close enough that we'd probably want a simliar test for both... and the fix could turn out to be related too. So I'm pushing this back to Drupal 8 for now.
Also, in the Drupal 7 patch it does all this:
But then, contrary to the code comment, it also removes taxonomy_field_presave() and replaces it with other functions. Does it really need both changes in the same patch? Looks like maybe taxonomy_field_presave() could be left alone...
And while the patch does appear to work, it seems like it should not be waiting until the first person creates a node to actually create the term - wouldn't it make more sense to create the term right when the default value form is submitted? At least seems worth discussing if that's desirable/possible....
Comment #99
jibranautocomplete part of taxonomy is handled by entity reference so moving it to proper component.
Comment #100
torotil commented@David_Rothenstein
Yeah that D8 first policy. Having that in place even for bug-fixes is one of the major nuisances for working with D7. Essentially that means that D7 is getting security fixes only. I'd just wish the drupal.org front-page would say so.
You might find some answers to that question in #67 … if you cared to read them.
Comment #101
davidhernandezI just experienced what David_Rothstein wrote in #98.
On HEAD, fresh install of D8. Edit
field_tagson the Article content type. This is an entity reference to the Tags vocabulary. Enter a term that does not exist as the default value, and click Save settings.Fatal error:
Fatal error: Call to a member function uuid() on a non-object in /Applications/MAMP/htdocs/d8/core/lib/Drupal/Core/Field/EntityReferenceFieldItemList.php on line 115This is a fatal error on an admin screen, using default settings from the installation. If this issue is to address that bug, this should be bumped to critical. If not, let me know, and I'll open another issue.
Comment #102
jhedstromHere's an attempt to address the issue.
Comment #105
amateescu commentedThe fix and the test looks good to me, thanks @jhedstrom! :)
Comment #108
amateescu commentedBad bot!
Comment #111
amateescu commentedThe 8.0.x patch was committed by @catch, moving back to 7.x.
Comment #112
jibranComment #113
torotil commentedI think it is not desireable in D7 because of the lack of UUIDs. If we'd create the tags upfront like in D8 it would mean the content-type config is at least harder to deploy.
You're right - the comment is wrong: hook_field_presave() won't handle these cases (#1994594: hook_field_presave() not called reliably). Thus hook_field_insert() / hook_field_update() must be used. IMHO the only thing left to do is to update the comments.
Comment #114
torotil commentedHere is the patch from #91 with updated comments.
Comment #116
mikemadison commentedJumping on the bandwagon, I am suddenly having this error, however it is happening in reverse (when people attempt to create taxonomy terms using the autocomplete, not when they leave the field null). In my case, the taxonomy field is inside of a field collection.scratch this comment, found an error in code logic causing this error, but for an unrelated reason
Comment #119
jibranLet's close this and move the patch to new issue for 7.x
Comment #120
jibranNovice Task:
Thank you!
Comment #121
jibranComment #124
torotil commentedI think the Drupal community has a serious issue with dealing with issues like this. The process established here on drupal.org actively prevents people from fixing bugs in D7 and that’s not since D8 was released but since 2013 in this case. This ticket has a history of:
This is for a major issue.
So basically D7 developers get either of two treatments “patch is ignored” or “the bar is raised” — sometimes and alternatively also “it’s too late now to introduce this kind of change” (after ignoring the patch for years). This has been the case in many other issues as well.
Anyway here is the “new” D7 issue: #3091311: Fatal errors during or after adding default values for autocomplete widgets (D7). I’m taking bets on how long it is ignored.