Closed (fixed)
Project:
Category
Version:
master
Component:
Code
Priority:
Critical
Category:
Bug report
Assigned:
Reporter:
Created:
3 Aug 2006 at 16:52 UTC
Updated:
28 Mar 2007 at 05:00 UTC
Jump to comment: Most recent file
I was having problems with a category that had multiple parents support: It kept adding the container to the parent list when creating a category.
I finally tracked this down to the use of $node->parents[0].
It seems that when the multiple-select list is used (i.e. activeselect isn't installed,) the $node->parents array ends up looking like this:
array(
73 => '73',
82 => '82',
);
instead of this:
array(
0 => '73',
1 => '82',
);
(although I haven't tested how it works with activeselect)
so, of course, $node->parents[0] doesn't exist, even though there ARE parents selected.
After applying this patch (attached) to de-key the $node->parents array, I am able to create categories without them having the container as a parent.
| Comment | File | Size | Author |
|---|---|---|---|
| #55 | dup_entry_still_alive.gif | 15.05 KB | venkat-rk |
| #47 | category.inc_2.patch | 521 bytes | bdragon |
| #37 | url_alias_field_after_bdragon_patch.gif | 1.95 KB | venkat-rk |
| #36 | cat_pathauto_after_bdragon_patch.gif | 15.42 KB | venkat-rk |
| #35 | category_pathauto.module.patch | 1.02 KB | bdragon |
Comments
Comment #1
Bèr Kessels commentedI ran into the same issue.
Though I am not sure about whether or not this is the proper solution (I understand too little of category) It /does/ fix the bug.
Comment #2
Bèr Kessels commentedFWIW, this patch fixes the "SQL error" bug #70229 too, it seems.
Comment #3
bdragon commentedIn my opinion, the "most proper" way of handling this would be to have the form give the user the option to specify the "primary parent" of a category directly, instead of always (well, trying to, at least) selecting the first one in the parents array.
Then, during form validation, ensure that parent (not to be confused with parents[]) has a sane value. If the user didn't specify one, grab the first one out of the parents[] array as before.
I just noticed there's actually a piece of code in category.inc:category_get_form that tries to let the user specify the primary parent by hand:
It will never kick in, though, because the function doesn't ever get $set_default from anywhere. It also isn't very user friendly.
How about a collapsed fieldset with title "Primary parent (optional)" that contains a subform to single-select a parent, with the subform defaulting to "<automatic>" or something if parent isn't set? During validation, if the user chose a primary parent that wasn't selected in the main parents[] selection, add it to the parents[] array.
That would allow the removal of all the instances of parents[0] in the code, I believe, and be both more flexible and less prone to error.
I could make a patch for this if anyone's interested.
Comment #4
drurian commentedCan you make it please?
Comment #5
bdragon commentedIt appears that my "most proper" suggestion is flawed, and this is indeed just a simple bug.
After reading the code, I see that the order of parents is determined by a) The parent containers' weight, and then b) The parent containers' title. Then this information is thrown away (another bug, it re-sorts by CID accidentally).
The elegant way of allowing parent ordering per category would be to add a weight field to {category_hierarchy} and add h.weight to the beginning of the ORDER BY clause in category.inc:category_get_parents.
Right now though, I'll write a patch to fix what I percieve as being the intended behavior: The lowest-weight category will be the primary parent.
Comment #6
bdragon commentedHere's the patch.
All the changes are in category.inc.
I changed category_get_parents to honor sorting, which made it an indexed array.
I changed an instance of relying on category_get_parents to return cid's as the keys.
Any instances of
need to be changed to:
This probabaly fixes odd sorting bugs in the category chooser as well.
Please test.
Thanks.
--Brandon
Comment #7
bdragon commented(updating title, raising priority, assigning to self)
Comment #8
bdragon commentedI need to check category_display, category_export, category_legacy, category_menu, and contrib still.
I'll make patches as I go along.
Comment #9
bdragon commentedCategory_display:
0 modifications needed.
1 bug fixed just from having the new code in:
Comment #10
bdragon commentedcategory_export:
0 modifications needed.
0 bugs fixed.
category_menu:
0 modifications needed.
Possibly many bugs fixed.
Seen:
Assumption in menu logic, Probabaly causing missing or broken menus. (line 215.)
Evidence of a bug workaround seen (line 226) (may be removed now)
Same workaround on (line 333)
Possible bug on (line 369)
Comment #11
bdragon commentedcontrib/cac_lite:
0 modifications needed.
0 bugs fixed.
contrib/category_bulkedit:
0 modifications needed.
Possible bug on line 502.
contrib/category_outliner:
0 modifications needed.
0 bugs fixed.
contrib/category_pathauto:
0 modifications needed.
0 bugs fixed.
Workaround found on line 84.
contrib/category_transform:
0 modifications needed.
possible bug on line 175, fixed by patch.
contrib/category_views:
0 modifications needed.
0 bugs fixed.
Comment #12
bdragon commentedLast but not least, category_legacy:
category_legacy_build_category_from_term appears to key the parents array too.
This could possibly cause terms to get forced to have the container as a parent during import.
Possible bugs on lines 1319 & 1409.
Here's a patch to de-key category_legacy_build_category_from_term. I don't have anything to test it on.
In addition, $parent_map should be passed by reference for speed. I also updated the doxygen documentation for the functions that use a $parent_map.
Comment #13
venkat-rk commentedWhich of these three patches (the one in the original post, #6 and #12) should be applied? Or should all the patches be applied? In any particular order? I am willing to test this out.
Could you please provide category_array_fix.txt as a patch file?
Comment #14
bdragon commentedThe patches to apply are #6 and #12. Order isn't important.
OP fixed a problem where the container would get added to the parents list in a container with hierarchy set to "multiple."
#6 supersedes OP. It changes the behavior of category_get_parents to return a non-associative array that is sorted properly.
#12 makes category_legacy create de-keyed arrays like the new behavior of category_get_parents.
category_array_fix.txt is in fact a patch file, I just screwed up the file extension when I made it.
I'm expecting the sorting in the parent selector to be different than pre-patch, as sorting was previously broken in category_get_parents. Adding weight to categories will make them move around in the list. Also, a category with multiple parents will have the first match as its primary parent.
I'm hoping this fixes more bugs than it introduces.
Comment #15
venkat-rk commentedThank you bdragon. I am going to jump into this headlong. I have invested too much time in category module not to. I rarely use multiple parents, but do use category_legacy frequently and hope this will solve the bugs. I experienced the category_hierarchy bug just today when using category_legacy.
Comment #16
venkat-rk commentedI applied both the patches. Now, when I create a container, I can see the container hierarchy in the parent select drop-down. I don't remember having seen this earlier. Is this correct?
In the attached screenshot, 'Find' shows up as the child container of 'Find Section', a hidden container. This is exactly the way I set it up. I don't remember this ever having worked this way.
Yet to test category_legacy. Unfortunately, I trashed a large test site built on taxonomy so I don't have much data. Will create another test site and report this later.
Comment #17
venkat-rk commentedOn a hunch, I decided to try category_pathauto, which has been broken for the last month or so after applying these patches. Good news- it works. No more problems as reported in the issue queue.
Bulk update still has problems creating the correct category paths, as does the creation of an alias when you manually remove the exisitng one from the 'Url path settings' field, but it works cleanly by and large.
Comment #18
bdragon commentedWell, as far as I know, without the patch, parents were getting sorted by id, so it was possible to end up with things in the wrong order, like
Was "Find Section" supposed to disappear from the list?
That's good to hear.
I'm most curious about category_legacy. I wasn't able to test my changes to it (no legacy data), and I'm not familiar with what's "normal," as I haven't actually used it before.
--Brandon
Comment #19
venkat-rk commentedI don't really remember as I haven't been using category for about a month now.
The 'Find' container wasn't meant to disappear, so everything is working as it probably should. May be I should test category without the patches on another site to find out the exact differences. I will try and set up a test site for category_legacy as I am curious about it too.
Comment #20
venkat-rk commentedI want to add that while these patches have made category less buggy, the category map problem still persists. Unfortunately, I wasn't paying attention to what I was doing, so I am unable to report the exact sequence that caused the error.
category_pathuto is still largely broken (edit a container/category or node- pathauto will report the alias as having been created but nothing happens really. Only works when you manually enter the alias and save), but I will report that in its own issue.
Comment #21
venkat-rk commentedOne problem after applying the patch:
If I have a regular or free tagging category under a hidden container and I create a node tagged with that category, this category is not picked up during breadcrumb generation.
As a result, on the node page view, one gets just the 'Home' link in the breadcrumb trail. This breaks the hierarchical menu tree generated by cat_menu too.
At least, this is how the problem appears at first glance. Screenshots to follow.
Comment #22
venkat-rk commentedIn the attached screenshot, the node has been tagged with the category 'News' which is under a hidden container. Notice that the 'News' link is not shown in the breadcrumb trail.
Comment #23
venkat-rk commentedThe container in question here is 'Spirituality'. It has a hidden container called 'Site Sections' as its parent. 'Discourses' and 'Festivals' are categories created by free tagging. The node displayed in the sceenshot is tagged with both the categories. All good so far.
Comment #24
venkat-rk commentedEverything breaks on the node view. See the collapsed cat_menu tree on the left and the absence of breadcrumbs at the top. It is not an url alias issue, as you can see from the url in the browser.
Comment #25
venkat-rk commentedFrom what I have seen so far, the issue seems to be only when hidden containers are used. For a container directly under root, the breadcrumbs are correctly generated.
See attached screenshot where the container 'Projects' is directly under root.
Comment #26
bdragon commentedLooking into this now.
Will re-evaluate category_menu for side effects involving hidden containers.
Comment #27
bdragon commentedWhat happens if you mess with the weight of the hidden container?
Comment #28
venkat-rk commentedThanks for looking into this.
I just tried changing the weights of the hidden containers around. For good measure, I resaved the nodes tagged with categories in those containers. It didn't help, unfortunately.
Comment #29
bdragon commentedFound a *potential* error: Only the first parent was being checked here.
Does this make things better or worse?
Comment #30
venkat-rk commentedThanks for the quick assistance. Much appreciated. It is past midnight here, though, so I will report back tomorrow after tyring the patch:-)
Comment #31
bdragon commentedI modified "category_breadcrumb.module" to get breadcrumbs working nicely.
http://drupal.org/node/75276#comment-134905
It _should_ take the lightest weight path back up to the root. I have not extensively tested all this, but it appears to work.
Right now I'm too tired to test this further. Please tell me if this solves your problem.
--Brandon
Comment #32
venkat-rk commentedI applied the patch and resaved the nodes in question, but with no apparent effect. The problem remains.
I am loath to applying the category_breadcrumb.module as it is in the 'wild' at the moment and because category otherwise never has a problem with generating correct breadcrumbs.
Comment #33
venkat-rk commentedI also tried the following, resaving the nodes on each occasion, but without results:
1.) Changed the weights of the free tagged categories to both positive and negative values instead their current 0
2.) Changed the depth of the free tagged categories to an infinite value (-1) even though they didn't have child categories
3.) Changed the depth of the hidden, top level container that holds all the site's containers to an infinite value (-1)
Comment #34
bdragon commentedAhh.
No wonder I couldn't figure out where the breadcrumbs were coming from. I totally forgot about category_pathauto.
I suspect if I check for bugs in category_pathauto, I may find a proper solution to this.
Comment #35
bdragon commenteddoes this patch change things?
If it does, I believe I have a very good idea of what's wrong.
Comment #36
venkat-rk commentedWhoops! Some bug here.
A few things are noticeable:
1.) The patched cat_pathauto now leaves out the container (musings) from the alias and takes the first category. But the browser url points to the full path
2.) The breadcrumb still doesn't reflect the full hierarchical trail- 'Frugality' is missing
Comment #37
venkat-rk commentedMost interesting.
If I click on the edit link of the node that showed the error and look at the url path settings, it shows the full path (including 'musings'). This is contrary to the message that pathuto printed out to screen.
Comment #38
bdragon commentedRight. I wasn't fixing the general case. I was only fixing _category_pathauto_get_path, and only for the case where the issue was with the immediate parent.
The underlying problem appears to be an assumption in category_location that following the chain of $node->parent is "good enough" to find the root.
Rewriting category_location to "try harder", so to say, should fix all of this for good.
Comment #39
bdragon commentedWell, THIS is interesting:
Checking the return value of category_location:
Note the parent of the last object. It is pointing to *itself*
This may also be what's causing the "duplicate category at end of list" problem with nodes.
Hopefully I can figure out why this is happening...
Comment #40
bdragon commented*slaps forehead*
It's not pointing to itself, it's pointing to the container that was left out due to being hidden.
Comment #41
bdragon commentedOk, now that I actually know how pathauto works (sigh)
The real problem is containerfirst being the wrong container, causing pathauto to not be able to find the correct path.
Comment #42
bdragon commentedcategory_pathauto_get_placeholders needs to take into account hidden containers. $node->cnid may not be a valid point on the menu.
Will think about this further.
Comment #43
bdragon commentedOk, after thinking about it a bit, I realized that it may be impossible to unambiguously identify nodes without having hidden containers in the path.
Consider:
Node 1: title "An Article" categories{Sport=Baseball}
Node 2: title "An Article" categories{News=Baseball}
Node 3: title "An Article" categories{Something=Baseball}
Which node do I mean when I ask for /news/baseball/an_article?
Which container is responsible for the path /news/baseball?
Comment #44
venkat-rk commentedI am just as stumped by the pathauto stuff, but I don't have your level of technical understanding even to suggest something:-)
One other issue I noticed with these patches (only #0, #6 and #12). If I click on create content and try to add a category under <root>, I can't! I am forced to put it under some existing container or create one just for this purpose.
I am a little confused as I think the default behaviour of category module is different and let you add a category under root. Might be wrong, though.
Comment #45
bdragon commentedWell, my last question is more of a classification question than a technical question.
My thoughts:
Possible solutions?
Deeper thoughts, meta-thoughts.
I'm not an expert in classification. I'm not an expert in SEO. I can't see the big picture. I'm not an architect. I'm just a coder in the trenches. As such, I don't know what the *expected* behavior is.
Ramdak: What would fufill the "principle of least suprise" for you? I.E. in a perfect world, what would you expect to happen when you put an item in a category in a hidden container? How would the menu look? How would the URL look? How would the breadcrumb look?
I have seen the code. I am biased. Any solution I propose is likely to be in terms of the code already written. It would be a tragedy to trade one tradeoff for another when a superior solution existed all along, but everyone with the skill to implement it was so locked into the mindset of the current code that they never realized it.
Are hidden containers the solution? Is there a better way?
Back to normal
Sorry about the philosophy there, but I really needed to say it. :)
While I have the capacity to find bugs in code, I don't really have the capacity to find bugs in processes.
--Brandon
Comment #46
venkat-rk commentedBdragon, I stepped away from this a bit to get some perspective. But, to respond:
1.) When category_pathauto was initially released on 1st June, it worked perfectly with hidden containers- they would ignore those containers and display perfect urls and breadcrumbs. And, although I frequently got the duplicate entry error for category_map or category_menu, distant parents worked fine in conjuction with cat_pathauto. I can say this for sure because I tested a lot
The problems began to surface around mid-July I think when category_pathauto broke. I don't know if this is because of changes to that module or to category. I would hazard a guess that it is the latter.
2. ) To respond to your question- I think my comment above perhaps answers it:-)
I would expect a hidden container to stay hidden because it is there for creating structure, not for categorisation and it is this combination that category module set out to achieve (and almost has), to put things rather simplistically. So, when I use hidden containers and cat_pathauto in conjunction, as a lay user, I expect the hidden containers not to show in the breadcrumbs and cat_pathauto to ignore them and still build correct urls that traverse the category hierarchy (which obviously includes the hidden containers).
I think hidden containers is one of the most important features of the module. One simple example - with it, you can have a category hierarchy that has several child containers each meant for content related to only one node type and taggable by categories relevant only to those node types. By simply placing a hidden container as the parent of each child container in the hierarchy and then creating specific categories as children of that child container, the node form for tagging that content type presents a great improvement for the end user. This isn't possible with core taxonomy- node types can be only defined at the vocabulary level globally as there is no concept of child vocabularies.
In sum, it appears (I haven't rigorously tested it) that the regular category module, despite its many duplicate entry error issues, doesn't have a problem generating correct breadcrumbs and menu items when hidden cotainers are used. However, since mid-July, category_pathauto is broken.
Your patches fix many underlying bugs *and* makes category_pathauto work again, but make breadcrumbs for categories and containers under hidden containers disappear from the breadcrumb, thus breaking the tree view of the cat_hierarchy at node level. Sigh:(
I want to reiterate again that your help has made working with category module possible in Jaza's absence.
Comment #47
bdragon commentedIt's 2AM right now here, but I thought I should probabaly follow up with a quick note before going to bed.
(quick note it was not -- ended up doing about half an hour of research....)
Mid July.... Mid July.... I'm betting July 10. There were multiple changes with the menu stuff on July 10.
This one makes me wonder:
I wonder what would happen if you tried THIS. (This patch should neutralize the change from the above commit.)
It's 2:30 now. I really need to get some sleep. Next week is finals week, so I may be a bit less responsive than I have been lately, but I'll keep working on this when I find time.
Comment #48
Jaza commentedI have committed the patches submitted by bdragon in #6, #12, and #29 to HEAD and 4.7. I also committed a few other changes that were needed to make this new version of category_get_parents() work properly, such as changes to the activeselect callback implementation, and changes to the taxonomy wrapper.
Thankyou very much Brandon (bdragon) for your hard work in debugging and patching this issue. I think that your solution provides a more reliable and consistent system for category_get_parents(), and it's clear that it has fixed quite a few category module bugs in one fell swoop. Just how many bugs (and which ones), I'm not quite sure. Thanks also to Ramdak for your testing and feedback in this thread.
I've done a fair bit of testing of this patch (along with my changes), and I wasn't able to find any new problems that it introduced. However, my testing was not particularly extensive. For this reason, I have marked this patch 'ready to be committed' (although it already has been committed) - to indicate that testing of the updated category module is needed, and that further patches may be needed in order to 'clean up any damage' that may have been done as a side effect of this patch going in.
btw, bdragon, I see no reason why I should commit your latest patch in #47, which attempts to undo a bug fix that I committed a while ago. If you can provide some further insight into why you think the $cats_flat thing should be removed, please post your patch and reasoning in a separate thread. Thanks.
Comment #49
bdragon commentedYou are absolutely correct. #47 is not meant to go into CVS, and it does attempt to undo a bugfix. I should have posted it inline instead of attaching it. Sorry about that.
I've been trying to figure out why breadcrumbs stopped working properly when hidden containers+category_pathauto were used, and #47 was an attempt to see if the $cats_flat stuff was the culprit. TBH, the hidden container stuff in this thread probabaly belongs in a seperate issue completely, but it got mixed in with this issue because I originally thought it was fallout from my changes.
Comment #50
bdragon commentedI created a new issue to continue discussion on the breadcrumb & hidden container problems.
http://drupal.org/node/84643
Comment #51
Ken Watts commentedI think what just happened to me is related to this thread. I should warn you that I'm really new at this, so I'm never sure if my problems are bugs or newbie functions.
I set up a site in a development environment that was working perfectly. As part of that site, I had put the following code into the category.inc file:
I'm not at all sure that was the right place to put it, but I tried several other locations, and that was the only one that worked. It allowed me to use the parent name within a node by inserting the following code:
It worked perfectly.
But when I started to set up my site on a hosted server, I used the most recent version of drupal, and the most recent version of the category module (9/17/06).
Now I have two problems, which I think may be related to this thread.
First, drupal recognizes the function, but it doesn't find a parent (I put a message between the single quotes in the function, to test this. The message prints to the page, where I used to get the name of the parent category.)
Second, when I adusted the weight on one of my categories, and clicked on "Save categories and containers" on the category page, I got the following error messages.
Duplicate entry '2-3#' for key 1 query: INSERT INTO category_cont_distant (cid, allowed_parent) VALUES (2, '3#') in /home/dailymull/domains/dailymull.com/public_html/dev/includes/database.mysql.inc on line 120.
Duplicate entry '2-0' for key 1 query: INSERT INTO category_cont_distant (cid, allowed_parent) VALUES (2, '0') in /home/dailymull/domains/dailymull.com/public_html/dev/includes/database.mysql.inc on line 120.
Duplicate entry '1-0' for key 1 query: INSERT INTO category_cont_distant (cid, allowed_parent) VALUES (1, '0') in /home/dailymull/domains/dailymull.com/public_html/dev/includes/database.mysql.inc on line 120.
Duplicate entry '1-0' for key 1 query: INSERT INTO category_cont_distant (cid, allowed_parent) VALUES (1, '0') in /home/dailymull/domains/dailymull.com/public_html/dev/includes/database.mysql.inc on line 120.
My apologies if this is a red herring, but it seems to fit the pattern in this and related threads.
Thanks
Comment #52
Ken Watts commentedSorry--correction: the version of the category module I'm using is 9/19, not 9/17.
Comment #53
Ken Watts commentedOkay, I think I'll stop making these posts until I know more.
The problem with the function was my fault--I had some settings wrong. So that has nothing to do with this thread, and I apologize.
The error messages still seem to be connected, as far as I can see now.
Comment #54
marcoBauli commentedJust tryed the latest 4.7 release with category_get_parents fixes, and seems to work.
Also combined with the category_breadcrumb.menu at http://drupal.org/node/75276 outputs nice breadcrumbs that reflect the category hierarchy (with previous versions that didn't work).
I didn't deep test (not more than 20 minutes) but wanted to write this rather than forgetting to give any feedback.
Comment #55
venkat-rk commentedThe duplicate entry issue is alive and kicking. It hit me a while ago when I tried to convert a taxonomy based site to category by using category legacy to import the stuff. I downloaded and installed the category module just a few minutes ago, so this bug is still there in the latest version.
Jaza, Bdragon, should I submit an issue against category_legacy or will this do?
Comment #56
bdragon commentedSorry about that, Ramdak.
I totally spaced it. The patch in the *original post* was the patch to fix the duplicate parents issue, and it never got in.
Please check http://drupal.org/node/92818 for an updated copy of the patch.
Comment #57
Jaza commentedMarking this issue fixed, since http://drupal.org/node/92818 has now gone in, and since nobody has reported any problems specifically related to the commit announced in #48 (above).
Comment #58
venkat-rk commented@bdragon: Thanks. Does this mean that the fix in http://drupal.org/node/92818 committed by Jaza takes care of this and the problem reported in the other thread?
Thanks.
Comment #59
bdragon commentedIt will take care of the duplicate entry problems. The hidden container problem may still exist though...
Comment #60
(not verified) commentedComment #61
summit commentedHi,
I open this bug report again.
I am using the latest category module (version v 1.100.2.26 2007/02/02).
When making a translation with localizer module. I get the duplicate entry error with category_cont_distant:
Duplicate entry '590-0' for key 1 query: INSERT INTO BEST_INFO_category_cont_distant (cid, allowed_parent) VALUES (590, '0') in /home/beontop/domains/agim.nl/public_html/includes/database.mysql.inc op lijn 120.
Please help.
Thanks in advance,
greetings,
Martijn
www.best-information.eu
Comment #62
sunPlease open a new issue for that. This thread is far too long to maintain.