Closed (outdated)
Project:
Computed Field
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
26 Mar 2009 at 00:59 UTC
Updated:
28 Oct 2017 at 09:54 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #11
Moonshine commentedInteresting... while I think this change should be fine, I'd like to run a couple questions by yched first. So this one is pending a couple answers.
Comment #14
andreiashu commentedI got here because I have the same problem with Computed Field tokens and auto_nodetitle.
Thanks for the fix matt, even if it is not approved yet :)
Cheers !
Comment #24
what4software commentedI understand the fix but I cannot get it to work for me. After I change the code all I get is a blank page after hitting save.
I changed the following:
FROM
TO
Did I miss something? I am using computed_field 6.x-1.0-beta2 with token 6.x-1.12
Thanks
Comment #25
andreiashu commentedJust wanted to give some feedback about this approach: we applied the "patch" and everything works as expected. I have this on a live website.
@what4software, that is because you did it wrong :)
From
It should be:
Comment #26
andreiashu commentedAnd here is the trivial patch against the latest beta3.
Comment #27
andreiashu commentedUpdating the status so maybe we can get some maintainer feedback.
Comment #28
aterchin commentedpatch is good for me too.
Comment #29
Gerald Mengisen commentedPatch works for me, too (had the same problem with auto_nodetitle, token and one single computed field in the title)
Comment #30
csc4 commentedSubscribing
Comment #31
TripleEmcoder commentedSubscribing.
Comment #32
Bilmar commentedpatch was successful for me as well - thanks for the great work!
i'm glad i came across this thread
Comment #33
netbear commentedMay be this patch will solve the problems like described in this topic: http://drupal.org/node/350404
Comment #34
matt2000 commentedI don't have access from my current location to my original code to check how I did it before, but I'm wondering if having both case 'insert' and case 'presave' is redundant?
Comment #36
amir simantov commentedI have a strange thing happening. After applying the patch I get memory exhaust in the coming module (content.module - comes lexicographically after computed field). Memory is not really a problem - I have increased it and looks like there is a loop or recursive call. That is, because the needed memory is doubled whenever I double the memory limit. Please mind, however, that the code has run OK before applying the patch, but, of course, could be used after second saving (while editing) - the problem the patch comes to solve in the first place. Following is the code I am running; it is a double inner join query. It is used in order to get the title of an object of type org (organization). An og object refers to an org, and a wiki node is bound to an og node; I want to save the name of the org in each wiki node in order to use it in a pathaufo pattern.
Please note that I tried also "node_save($node);" instead of "node_save(&$node);" - no difference; system crashes.
Any help will be appreciated, thanks.
Comment #37
hanno commentedpatch worked for me.
Comment #38
Moonshine commentedIt's been waaaay too long. :/ While adding it to the "presave" op should work, it would also result in the computation happening twice per node save. (presave/insert or presave/update). Probably not a big deal for most people, but for those with "expensive" computations that pull from outside sources or DBs that might be rough.
I committed a change from insert/update to presave alone, which will show up in the next dev download on the project page. I think that should do it unless there is some sneaky time when presave isn't run. After I get confirmation this is working and look through the queue a bit more here we'll get this thing out of its eternal beta.
Comment #40
jarnoan commentedI have a similar problem as Amir in #36. Calling node_save($node) in the field computation code causes a segmentation fault. I haven't digged deeper on the issue, but this started to happen after upgrading Drupal from 6.17 to 6.19, Computed Field to 6.x-1.0-beta4 and dozens of other modules to their latest versions.
Edit:
This is my super-elegant workaround:
Comment #41
catellani.m commentedSame Issue for me. System crashes while I try to create a new node.
This is the computed code:
if (!$node->nid) {
node_save($node);
}
$node_field[0]['value'] = $node->nid;
And this the display format:
$display = l(t('Visualizza la mappa per questo evento'), 'mappa_evento/'.arg(1));
I use drupal 6.16 and computed-field 6.x-1.0-beta4.
I've the same code on a computed field in a site with drupal 6.13 and computed-field 6.x-1.0-beta3 without problems
Comment #42
YK85 commentedComment #43
YK85 commentedthis may be what caused #945712: upgrade from beta3 to beta4 causes Error 324 (net::ERR_EMPTY_RESPONSE): Unknown error.
Comment #44
bibo commented@Moonshine
Unfortunately leaving the insert hook out DOES create problems in some situations. To be specific, we might need the node id available. I actually spent more time than I like to admit with debugging a problem caused by the latest update (in beta-4 and the dev-version).
In my setup computed field is used to create a kind of unique field from the node id. This unique id is then used in the nodetitle (with token + autonodetitle) and the alias (token + patchauto). During the creation an email will also be sent.. and after beta-4 this link no longer worked (because the computed_field-token had not been specified in time). Updates to the node would then sent emails with the correct link, though.
Anyway, in my case I wasted so much time searching for the problematic module, as I first couldn't find when the problem started. I suspected token, messaging, notifications, team_notifications, pathauto, module weigths and what not, before I found the actual cause: computed_field no longer updating it's value during insert!
Problem in short:
Node id is not available during "presave", if the node is new. However, the nid IS available in the insert-hook of new nodes. In other words:
New node hooks
* .. other hooks..
* presave (no nid)
* insert (got nid!)
Old node update hooks
* .. other hooks..
* presave (got nid!)
Proposed solution
If we need to use the nid during code evaluation, and want to avoid duplicate runs, we could just alter a few lines in the field_hook:
I tested this, and for me it works without problems. Got nid, no duplicate execution and therefore there should also be no infinite looping. Please test the attached very simple patch againt the latest dev-version.
The first line could be skipped (=run during both insert and presave hooks might also have some justification?).
EDIT: set this to major, as this "new" logic breaks any all sites using $node->nid in the evaluated php (and need it to work during first insert).
@jarnoan
<smartass-mode>
A global variable would stop the execution of any node save during the page load, meaning that it would only work for the first node, and not during any subsequent node saves (for other nodes). IMO this would be a bit more "elegant":
</smartass-mode>
Comment #45
roball commentedGood point. also got a WSOD when trying to use node_save($node) in the computed field code.
Comment #46
VJV commentedThanks bibo
I am use -beta4 and #44 solution was great for me.
I was not able to get NID when creating new node. Now it works like it should be.
Comment #47
pfaoclePatch in #44 in testing on a dev site here: seems to work although I've not tested heavily to see if there are any other upshots/side-effects to the change. The computed field I'm working with uses
$node->nidand a call tol()to add a link to the node itself (amongst other things). A simple version:Using the patch in #44 means the nid is now available for use in a link. The only issue I have now is that
l()generates a simple/node/nidlink, rather than an aliased path (which I assume pathauto generates AFTER computed field's hook_field/presave is called). Subsequently editing the node results in the correct URL alias returned froml(). Not really part of this issue, mind... but better than either producing a broken/node/link or causing a 500 server error!Comment #48
chuckbar77 commentedsubscribing, hope beta5 will be out soon as beta4 corrupts the site
Comment #49
bibo commentedThe "fix" committed in #38 caused many sites to break (including mine).
My simple patch in #44 seems to fix the problem. Setting to RTBC as per #46 and #47.
Comment #50
marktheshark commentedSubscribing
Comment #51
Moonshine commentedHmmm, I wish this would have surfaced while it was sitting in dev. :( Sorry for the delay, but until days have 36 hours...
The real problem is that this original issue was created to get Computed Field running during "presave" so that it would return tokenized values for Automatic Nodetitles. "Presave" would be ideal as it's run early and is triggered before any "insert" or "update". However, as @bibo notes, "presave" is actually too early to have the the NID assigned -- which I'm sure is a problem for some computed fields.
I'm afraid there really isn't a magic solution that I can see that will satisfy both the original issue and still have NID available to the the computed code without redundant calls to the field computation, which I think we need to avoid.
The patch in #44 will allow computed code to always have the NID available (as it had with the prior update/insert method), however it won't use presave on initial node creation which doesn't help the original point of this issue.
In the end I think we should go back to the insert/update method as Computed Field traditionally had, at least for the Drupal 6 version, for a few reasons:
I'll be rolling back this change in the dev branch and tagging a new beta 5 for now. If anyone has a magic answer that I'm overlooking, feel free to re-open.
When I get some time, I will look at how this works in the D7 version using the new Field API though. Perhaps there we'll be able to have it both ways.
Comment #52
Moonshine commentedI've moved things back to insert/update and tagged a beta5 release which should show up soon. Closing this issue for now, but as I mentioned, re-open if I'm overlooking something useful here.
I will be hitting the issue queue in the next couple weeks and pulling together a non-beta 6.x-1.0 release so that I can focus on 7.x a bit. Sorry for the delays everyone, I truly wish I had more time. At least CVS on drupal.org is going away this week, THAT is very exciting for me. I've never felt comfortable with it, and I can't wait for GIT! :)
Comment #53
roball commentedI have upgraded Computed Field from 6.x-1.0-beta4 to 6.x-1.0-beta5, but I still have the $node->nid not available in the Display format code (#982038: $node not available in the Display format code).
Comment #54
brad.bulger commentedjust a comment - maybe other people coming to this issue will be in the same position:
i can see the reasoning behind undoing this, but the main reason i was using a computed field in the first place was to get code out of the Automatic Nodetitle and out of the web interface in general - i was using a computed_field_FIELDNAME_compute() function to generate the title. the workaround that fit better was to do the actual computation in a hook_nodeapi() function on 'presave', and then leave the computed_field function there but do nothing in it, to avoid redundant calculation of the field value.
but that only worked OK for me because i didn't need the $field or $node_field parameters. maybe a way to help people deal with this problem would be a presave hook - computed_field_FIELDNAME_presave() ? or a more general hook run by computed_field_field()? or if there is already a CCK hook that could be used to the same effect that i've overlooked.
Comment #55
hanoiiSorry to bring this one to life.
Started to try computed_field, which I generally avoided by creating my custom modules. I came to this issue because I wanted auto_nodetitle to work with the tokens as well, although I understand that most things can be achieved on the PHP side of nodetitle, there's bit which is also not handled on this great module which is field validation.
Say I set it to required, I want it to validate that the computed field has something in it, and that's not working. It's kind of a separate issue but related to this one.
I understand the need of having $node->nid on current computed tokens but can a change be considered to also include validation, and why not, presave.
I was thinking of exposing $op to the custom_field php code. By doing that, you could query it on your code and act accordingly, whether having nid or not, or on each action.
I know this may make the code a bit more complicated, but well, isn't flexibility the main thing for this module?
Another idea, which may be backward compatible, and not one I'd like, is to store a separate computed code for presaving/validation.
I am not sure if I will follow this or just jump into doing some custom module development, but if this can be considered, I don't mind submitting a patch into it.
Comment #56
hanoiiAlso, thinking of not breaking current sites, I am thinking that if something like this might be considered (having $op), an update routine to add if ($op =='insert' || $op == 'update') { current code } to all existing computed_fields would sort any backward compatibility issues.
Comment #57
hanoiiComment #58
colanMarking #1081952: Compute values during "insert" and "update" rather then "presave" as a duplicate.
So it turns out that in D7, even though hook_field_insert() and hook_field_update() are being used, the field tokens are available (with a workaround for now - see #1280100: computed_field_tokens() does not check if $type == 'node' and blindly replaces tokens for all token types for details). So no re-jigging the API is not necessary for that branch. (Or if it is, and I'm missing something, please tell me.)
For D6, however, I'd be more than happy to accept patches that change the API to include $op. That's a good idea.
Comment #59
dqdDue to the Drupal core life cycle policy and security support advisery, Drupal 6 is no longer supported. So issues for Drupal 6 cannot be longer maintained. The project maintainer has asked for closing all D6 issues to clean up the issue queue. Feel free to reopen the issue if required or set it to "needs to be ported" and latest D8 dev version, if the issue discusses a still missing feature which can be implemented in the D8 version.
Comment #60
dqd