Weird Category Behavior because it starts with a number

Hi guys,

Recently bumped to latest and two of my categories pointed to one of them (say you have Category 1 and Category 2, both will show the contents of Category 1). This behavior is fairly weird already so, when trying to “unravel it”, I tried to change configurations on Category 2, which was the one showing the wrong posts. The changes were not saved regardless of the amounts of retries.

However, I tried changing the URL of the category to something else to see if that would force a reload or something, now if you click the category Discourse will just be stuck reloading without updating the URL to the category one. So, unless I’m missing something, now I’m unable to edit the category, since you need to enter it to edit it (I believe).

Already rebuilt our instance and all that, nothing changed, does anyone have a suggestion on what to do?

Thanks in advance.

1 Like

Maybe look at permalinks? A permalink is created when you rename a category. It could be that is causing the issue (I think it’d be obvious if that were the problem, but it’s all I’ve got).

2 Likes

Thanks for your suggestion @pfaffman

Indeed, there is a permalink for the category, but I still have the same weird behavior.

While playing with Permalinks, I think I understood the problem, “Category 1” has a normal name (ie: “Category”) but “Category 2” had a number name (ie: “11”). Turns out, what I think is happening is that since Category 1 has the “Category ID” which is the same number as the name of Category 2, everything is messed up.

Since the name change I did was to a bigger number just to try (from “11” to “111”) it is stuck loading… maybe because it’s looking for the Category ID “111”? Can someone confirm if this is possible?

1 Like

Does the category name start with a number? That might be a problem.

4 Likes

Yes, it is literally a number. :sweat:

3 Likes

Kept investigating:

  • Added Permalinks to both the old (“11”) and the new (“111”) names. No effect, keeps loading (had to guess the Category ID, don’t know if there is a way to check it somewhere).

  • Want to add something, the Category in cause is a Sub-Category (just mentioning it because looking at the URL I don’t know if it affects the output). So it is something along the lines of /c/ParentCategory/111

  • Is there a way to manipulate a Category if you can’t access it? To try to change the URL or something?

3 Likes

Hi again,

Kept trying different things within my limited knowledge. Unless someone points a way of editing a Category without accessing it, I’m without many ideas… is there a way to “move” all Topics on a Category to another?

Being that I can’t seem to solve this on my own maybe a way of mitigating it for usability would be to move it to a different one and leave the “zombie” one until someone has a better idea (because IIRC you can’t delete a Category without accessing it, so it would remain there, empty, on the list).

1 Like

:warning: Take a backup of your site before executing the commands!

cd /var/discourse
./launcher enter app
rails c
Category.find_by_slug('STARTING-CATEGORY-SLUG').id
Category.find_by_slug('DESTINATION-CATEGORY-SLUG').id
exit

Change STARTING-CATEGORY-SLUG and DESTINATION-CATEGORY-SLUG with the slugs of the starting and destination categories. The results will be 2 IDs.

rake categories:move_topics[STARTING-CATEGORY-ID,DESTINATION-CATEGORY-ID]

for example

rake categories:move_topics[11,27]
./launcher enter app 
rails c
c=Category.find(STARTING-CATEGORY-ID)
c.destroy
9 Likes

Hi @Dax,

Sorry on the late reply, tested, executed and solved my issue with these steps. Thank you very much for your help.

I want to give back somehow (even though my coding skills are not that good), is there a way to put a validation to avoid categories being numbers? Want to help with that.

Thanks everyone.

2 Likes

Thanks but our engineers have already a fix to prevent numbers from being inserted into the category slugs. As you discovered, currently having “11” as the category name is fine, but the slug for the category will need to be changed to something that does not start with a number, for example cat-11.

7 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.