Steps to reproduce:
1. Start to create an Article node ranting about the current President. Add a tag michele-obama-wears-combat-boots.
2. Preview the node.
3. Think better of it, and navigate away before saving the node.
4. Explain to the FBI guys who show up at your door to arrest you for defaming the first lady that actually it is the fault of a spikey-haired Belgian guy, not yourself, because you never meant to create that tag.
taxonomy_autocomplete_validate() calls taxonomy_term_save() for all terms that do not exist yet. I understand why it does: It needs to transform the form data to match what the field expects, which requires a tid, and also probably because of previous long-standing issues in which free-tagging terms did not work well with node preview. However, form validation (I thought) should not have any permanent side effects, and in this case it does. Questions:
1. Is it common in core for form validation to have side effects in the db?
2. If not, I'm wondering if we can find a way to avoid it in this case. Too tired to think about it myself right now.
Comment | File | Size | Author |
---|---|---|---|
#23 | taxonomy-freetag-validation-826028-23.patch | 9.72 KB | bjaspan |
#18 | taxonomy-freetag-validation-826028-18.patch | 9.82 KB | bjaspan |
#14 | taxonomy-freetag-validation-826028-14.patch | 1.64 KB | bjaspan |
#7 | taxonomy-freetag-validation-826028-7.patch | 4.64 KB | bjaspan |
#6 | taxonomy-freetag-validation-826028-6.patch | 4.21 KB | bjaspan |
Comments
Comment #1
Anonymous (not verified) CreditAttribution: Anonymous commentedI kinda know about this problem, and Barry's assessment of the problem is accurate.
(And if the FBI does show up, just show them the cover of the New Yorker 21 July 2008.)
And I'm too tired to comment further, so I am going to have to come back to it after coffee and not on Sunday.
Comment #2
catchSubscribing.
Comment #3
bjaspan CreditAttribution: bjaspan commentedHere's my first attempt at a solution. It seems pretty straightforward, I have no idea if it is a total kludge or a clever solution. :)
We really need an issue status of "testbot, please try this" so we don't have to embarrass ourselves my setting CNR when it isn't really ready. :-)
Comment #4
bjaspan CreditAttribution: bjaspan commentedDidn't mean to set critical at this time.
Comment #6
bjaspan CreditAttribution: bjaspan commentedOoops. Small fix.
Comment #7
bjaspan CreditAttribution: bjaspan commentedAdded explanatory comment and did some minor cleanup.
Comment #8
bjaspan CreditAttribution: bjaspan commentedBump, in hopes of catching a review. :-)
Comment #9
yched CreditAttribution: yched commentedmissed that one. subscribe
what happens with the patch when the user enters several non-preexistent terms before previewing ?
Comment #10
Anonymous (not verified) CreditAttribution: Anonymous commentedI like being rid of this. Was it doing anything useful anyway? I don't think it was.
I'm not going to bikeshed he name of a constant. But if I were going to bikeshed, I'd drop the FREETAG. But I'm not.
Otherwise? I think the patch is good. My assessment: clever solution.
@yched: I tested the patch by using three tags that didn't exist yet. They were all created after saving. Previewing the node did not create the terms. All the terms were still in the order I typed them in the autocomplete widget after preview. The autocomplete widget in taxonomy term fields does not rely on term IDs for passing around its values until the values are saved--if I'm reading your concern correctly.
46 critical left. Go review some!
RTBC!
Comment #11
yched CreditAttribution: yched commentedThe role of options_array_transpose() was to transform an array of $tids into the
array(... $delta => array('tid' => $tid) ... )
format expected for field values.
Definite +1 on removing it. I guess this was a remnant from when the 'taxo as field' widget code was split from optionwidgets, but here it's possible and indeed much better to directly build the array in the right format, which the patch does as a side effect of the general fix.
Patch looks good, so if bangpound is happy, then so am I.
Comment #12
bjaspan CreditAttribution: bjaspan commentedAs the author of the patch I'm no longer convinced it is right. As yched points out, it makes preview of new terms not work, and more importantly I'm suddenly getting some E_NOTICE errors. Working on it...
Comment #13
bjaspan CreditAttribution: bjaspan commentedWhile working on this, I discovered and submitted #844388: Taxonomy terms disappear from node preview if previewed more than once.
Comment #14
bjaspan CreditAttribution: bjaspan commentedNew patch. This makes free-tagging terms that do not yet exist show up in the preview as just a name, since they have no URI yet. It also turns out that rdf.module needed a patch because it also operates during preview assumes the terms exist.
If you press Preview twice on the same node you will get several warnings. That has nothing to do with this patch, and is fixed by #844388: Taxonomy terms disappear from node preview if previewed more than once.
Comment #15
bjaspan CreditAttribution: bjaspan commentedComment #16
bjaspan CreditAttribution: bjaspan commentedAsking the testbot if there are other problems like the one in rdf.module...
Comment #17
yched CreditAttribution: yched commentedHm, patch #14 only touches rdf.module ?
Comment #18
bjaspan CreditAttribution: bjaspan commentedOdd, cvs diff is not doing what I expect. New patch.
Comment #19
moshe weitzman CreditAttribution: moshe weitzman commentedUp priority due to FBI connection. And this is DB corruption IMO.
Comment #20
AaronBaumanyup, patch #18 works for me
Comment #21
sunum. That's a weird use of constants. Why don't we simply use a string 'new' or 'autocreate' or whatever, instead of this *heavy* indirection? Makes no sense to me.
At the very least, this could be a negative integer, since tid cannot be < 0...
Anything, else, please.
Powered by Dreditor.
Comment #22
yched CreditAttribution: yched commentedMinor : in order to have previews look accurate (i.e with links where there will be links), we should IMO generate a link to a new 'taxonomy/temporary' page, which only displays some text saying 'No content, this term does not exist yet'.
I guess few people click on taxo term links in previews anyway (since it reloads the page and kills you edits, unless you use a middle-button click), while the overall appearance matters more.
empty
else if
clause looks odd ?If something needs to be done in both 'insert' and 'update', then hook_field_presave() sounds like a better candidate - it's called before any of the two others, so execution order should be the same as in the current patch.
In which case, not sure this deserves a separate _taxonomy_term_autocreate() helper func ?
Other than that, the patch and the approach look good to me.
Powered by Dreditor.
Comment #23
bjaspan CreditAttribution: bjaspan commentedNew patch.
1. Replaced TAXONOMY_TERM_AUTOCREATE with 'autocreate'. Refusing to bikeshed.
2. Converted _taxonomy_term_autocreate() into taxonomy_field_presave(), per #22.
3. Added tests.
re: a link for a non-existent term, I think it is debatable. A themer can make such new terms look like whatever they want. I suggest this as a non-critical followup issue.
re: the empty "else if" block. I know it looks odd, and it would be easy to write it the other way (change == to != and then put the body of the else clause in it), but I think the code is clearer and easier to understand the way I did it. Does anyone object strongly?
I discovered via my new test that taxonomy.module has static caching bugs. I'll file a separate issue.
Comment #24
bjaspan CreditAttribution: bjaspan commentedRegarding linking for non-existent terms in preview, it turns out my current patch does what D6 did. From taxonomy_link():
So it seems clear we can leave it this way in D7 too.
Comment #25
yched CreditAttribution: yched commentedTrue. Looks good, then !
Comment #26
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD.