Accidentally Created Two Identical Categories. Something Broke


(jcan) #1

I must have clicked the create button when making a new category twice or something. Both categories show up in “All categories” page, with the same name, so they have the same URL. When I click on EDIT on one of the category’s pages it doesn’t open the edit dialog, so I don’t know how to delete them.
Anyone know how to resolve this?


(Sam Saffron) #2

@eviltrout how is this possible?


(Jeff Atwood) #3

Duplicate names are possible for subcategories, but should not be possible for categories proper.


(jcan) #4

I have no clue. I’ve only just gotten my feet wet when it comes to using Discourse.
Here’s my categories page: Link

And here’s a screen shot: Link


(jcan) #6

When I click one of those “Advertising” categories it brings me here, then hangs on “Loading…”

If I reload or manually enter the URL I get to the category page, but cannot get the Edit button to work.


(Robin Ward) #7

Is there any chance you created it as a subcategory then moved it to be a parent category?


(jcan) #8

I clicked the create button twice and it just made two categories. you can see in the screenshots. they are both somehow their own categories. is there a way to delete categories through my terminal, or something?


(Robin Ward) #9

That’s really weird because there is a constraint in the database to prevent the same category name from appearing twice. I have no idea how this can possibly happen even if you clicked twice but I will try to reproduce it myself.

To delete one of them, open a web browser while logged in to your forum and paste this into the address bar of your browser: Discourse.ajax("/categories/14", { type: 'DELETE' }) and hit enter. It should delete the category after you refresh your browser to the forum again.


(jcan) #10

I tried that ajax command. It’s not doing anything other then initiating a search (I’m using Chrome).

The only other thing I did besides possibly click twice on the button, is that I could have made the category’s sorting order 100 instead of 10.

There’s definitely two identical (broken) categories. See here


(Jeff Atwood) #11

Try entering it at the f12 console like so:


(Robin Ward) #12

Oops, I forgot to add javascript: in front. The full command for the address bar should be:

javascript:Discourse.ajax("/categories/14", { type: 'DELETE' })

Also doing what @codinghorror said will work!


(Kane York) #13

Chrome will strip the javascript: if you try to paste it - you must type it manually.


(jcan) #14

Thanks for all the help guys.
I just tried @eviltrout’s fix, worked like a charm.

Where’s the best place to learn more about javascript Discourse commands?


(Robin Ward) #15

Right now the only place to learn them in is the source, because they are considered internals. Normally you shouldn’t need them but this was a really weird case.

We’re working on plugin interfaces and extensibility for the future, to establish APIs people can build on.


(Robin Berjon) #16

FWIW we just had the same bug at http://discourse.specifiction.org/, where the “asm.js” category was created twice. I don’t know exactly how it happened as it was done by one of the moderators (who is currently sleeping), but I’m pretty much certain that it didn’t involve mucking around with subcategories as it was clearly meant to be top-level.

Every dialog I tested showed both categories appearing, with the same name and colours. Trying to edit either always edited just the first one (in ID order), I presume because the route matches on the name.

Interestingly, there was only one topic created under only one of those two identical categories but the little blue number counting the new topics reported two topics for both. I suspect that weirdness might point at what’s going on there.

Calling the deletion code provided here from the console just worked.


(Jeff Atwood) #17

@eviltrout we definitely need to add more safety here. Probably related to the changes we made to allow subcategories with the same name…


Should you be able to create subcategories with the same name as ones under another category?
(Robin Ward) #18

Do you have a backup of your database from before you removed it? I am curious is to how the row looked in the table, as it should not be possible to have the same title as a parent category due to a DB constraint. I am wondering if one version had spaces or other junk.


(Robin Berjon) #19

By luck, there was indeed a backup snapshot in between the creation and deletion. I’m happy to email you the full thing (LMK your address) or to paste a dump of the categories data somewhere if you reckon that’s enough.


(Robin Ward) #20

Amazing!!!

My email adress is my first name dot last name at gmail. I’d love to peek through and see how to fix this.


(Robin Ward) #21

I’ve just pushed out a fix for this, thanks!