Can't delete topic without category

I’ve a topic in our database with an category_id which category someone has deleted. I can open this topic directly with it’s id:
url: …/t/3

in table topics the id = 3 has category = 4. But this category is deleted and not in table categories. Many of this lost topics I could delete. But this one doesn’t work, cause attribute closed and archived are true.

If I choose in popup menu “Permanently Delete” this topic, I get error message:
“An error occurred: This topic has undeleted posts. Please permanently delete them before permanently deleting the topic.”

Any idea how to insert a dummy category with id 4 in database or to delete this lost topic?

I think that’s the About topic for the General category?. Normally the about topics would be undeletable in the UI.

Is there a reason you want to delete this one completely?

1 Like

cause this category isn’t more available, but which is more important: link to all categories in sidebar doesn’t work anymore.
If I try open …/categories I get errormessage: “Error Something went wrong.” and in browser console errormessage is shown:

Uncaught TypeError: i is null
    reason binary.js:7
    l item.js:166
    get topic.js:1017
    ee upload.js:65
    get topic.js:1017
    get topic.js:1017
    eM topic.js:1017
    s backup-codes.js:33
    n backup-codes.js:33
    Z upload.js:65
    T backup-codes.js:33
    evaluate backup-codes.js:33
    _execute backup-codes.js:33
    execute backup-codes.js:33
    rerender backup-codes.js:33
    render theme-setting.js:6
    _renderRoots theme-setting.js:6
    tA backup-codes.js:33
    _renderRoots theme-setting.js:6
    _renderRootsTransaction theme-setting.js:6
    _revalidate theme-setting.js:6
    invoke client-error-handler.js:88
    flush client-error-handler.js:88
    flush client-error-handler.js:88
    _end client-error-handler.js:88
    end client-error-handler.js:88
    _run client-error-handler.js:88
    run client-error-handler.js:88
    d bookmark.js:114
    Ember 2
    _join client-error-handler.js:88
    join client-error-handler.js:88
    p bookmark.js:114
    h bookmark.js:114
    $ topic.js:1017
    trigger composer-action-title.js:62
    transitionStarted add-translation.js:27
    loading ace-editor.js:176
    D upload.js:65
    triggerEvent upload.js:65
    trigger form-template-validation.js:54
    _handleSlowTransition upload.js:65
    invoke client-error-handler.js:88
    flush client-error-handler.js:88
    flush client-error-handler.js:88
    _end client-error-handler.js:88
    end client-error-handler.js:88
    _runExpiredTimers client-error-handler.js:88
    setTimeout handler*setTimeout client-error-handler.js:88
    _installTimerTimeout client-error-handler.js:88
    _later client-error-handler.js:88
    later client-error-handler.js:88
    T bookmark.js:114
    _triggerAction form-template-validation.js:54
    click form-template-validation.js:54
binary.js:7
Uncaught TypeError: i is null
    reason binary.js:7
    l item.js:166
    get topic.js:1017
    ee upload.js:65
    get topic.js:1017
    get topic.js:1017
    eM topic.js:1017
    s backup-codes.js:33
    n backup-codes.js:33
    Z upload.js:65
    T backup-codes.js:33
    evaluate backup-codes.js:33
    _execute backup-codes.js:33
    execute backup-codes.js:33
    rerender backup-codes.js:33
    render theme-setting.js:6
    _renderRoots theme-setting.js:6
    tA backup-codes.js:33
    _renderRoots theme-setting.js:6
    _renderRootsTransaction theme-setting.js:6
    _revalidate theme-setting.js:6
    invoke client-error-handler.js:88
    flush client-error-handler.js:88
    flush client-error-handler.js:88
    _end client-error-handler.js:88
    end client-error-handler.js:88
    _run client-error-handler.js:88
    run client-error-handler.js:88
    d bookmark.js:114
    success base.js:71
    l loader.js:1286
    fireWith loader.js:1286
    jQuery 4
    a base.js:71
    e named-references.js:49
    e named-references.js:49
    A base.js:71
    _findCategoriesAndTopics item.js:166
    k named-references.js:49
    w named-references.js:49
    invoke client-error-handler.js:88
    flush client-error-handler.js:88
    flush client-error-handler.js:88
    _end client-error-handler.js:88
    end client-error-handler.js:88
    _runExpiredTimers client-error-handler.js:88
    setTimeout handler*setTimeout client-error-handler.js:88
    _installTimerTimeout client-error-handler.js:88
    _later client-error-handler.js:88
    later client-error-handler.js:88
    T bookmark.js:114
    _triggerAction form-template-validation.js:54
    click form-template-validation.js:54
TypeError: t.category_list.categories is undefined
    s form-template-validation.js:54
    categoriesFrom form-template-validation.js:54
    _findCategoriesAndTopics item.js:166
    k named-references.js:49
    w named-references.js:49
    invoke client-error-handler.js:88
    flush client-error-handler.js:88
    flush client-error-handler.js:88
    _end client-error-handler.js:88
    end client-error-handler.js:88
    _run client-error-handler.js:88
    run client-error-handler.js:88
    d bookmark.js:114
    success base.js:71
    l loader.js:1286
    fireWith loader.js:1286
    jQuery 4
    a base.js:71
    e named-references.js:49
    e named-references.js:49
    A base.js:71
    _findCategoriesAndTopics item.js:166
    k named-references.js:49
    w named-references.js:49
    invoke client-error-handler.js:88
    flush client-error-handler.js:88
    flush client-error-handler.js:88
    _end client-error-handler.js:88
    end client-error-handler.js:88
    _runExpiredTimers client-error-handler.js:88
    setTimeout handler*setTimeout client-error-handler.js:88
    _installTimerTimeout client-error-handler.js:88
    _later client-error-handler.js:88
    later client-error-handler.js:88
    T bookmark.js:114
    _triggerAction form-template-validation.js:54
    click form-template-validation.js:54
Error while processing route: discovery.categories t.category_list.categories is undefined 3069/categoriesFrom/s<@https://forum.mydiscourse.de/assets/chunk.0144d0b7f03b4dd2b0a0.d41d8cd9.js:9:2817
categoriesFrom@https://forum.mydiscourse.de/assets/chunk.0144d0b7f03b4dd2b0a0.d41d8cd9.js:9:2809
11341/_findCategoriesAndTopics/<@https://forum.mydiscourse.de/assets/chunk.0144d0b7f03b4dd2b0a0.d41d8cd9.js:27:122623
k@https://forum.mydiscourse.de/assets/chunk.0144d0b7f03b4dd2b0a0.d41d8cd9.js:441:164470
w@https://forum.mydiscourse.de/assets/chunk.0144d0b7f03b4dd2b0a0.d41d8cd9.js:441:164363
invoke@https://forum.mydiscourse.de/assets/chunk.0144d0b7f03b4dd2b0a0.d41d8cd9.js:202:7701
flush@https://forum.mydiscourse.de/assets/chunk.0144d0b7f03b4dd2b0a0.d41d8cd9.js:202:6778
flush@https://forum.mydiscourse.de/assets/chunk.0144d0b7f03b4dd2b0a0.d41d8cd9.js:202:8650
... and much more
2 Likes

It sounds like someone deleted the category when it has topics in it somehow? That’s not supposed to happen. I think you’ll need to do something like

rails c
c=Category.last; # or some other way to get a category)
Topic.where(category_id: 4).update_all(category_id: c.id)

If your General category was deleted safely through the UI then it’s expected that the About topic would be soft deleted like you’re seeing. It shouldn’t cause any issues. :thinking:

I think there may be something else at play. Is there any more detail about that error in your /logs page?

1 Like

This seems not to work:

discourse(prod)> Topic.where(category_id: 4).update_all(category_id: 20)
=> 0
discourse(prod)> Topic.where(id: 3).update_all(category_id: 20)
=> 0

And in Data Explorer I get:

Select id, closed, archived, title,category_id
from topics 
where id = '3'

result:
id 	closed 	archived 	title 	category
3 	true 	true 	Über die Kategorie Team 	4

Hmm. I thought your broken topic had category_id of 4.

That was my best guess. If you have a budget you might ask for help in Marketplace. I think you’ll need someone to get into rails to see if they can figure it out.

1 Like

Marketplace is always an option, especially if it’s urgent. :heart:

Though a bit more detail here might help jimmy up a community response. :crossed_fingers:

You both seem confident that the root cause is this topic. If data explorer can find it then you should be able to find it in the rails console. If you can find it then you should be able to use post_destroyer on it and delete it from there?

(Though slightly hesitant to recommend it as I’ve not quite connected up the dots to where the issue is)

3 Likes

yes, in ruby console I can see that topic:

result = ActiveRecord::Base.lease_connection.exec_query('SELECT id, category_id FROM topics WHERE id = 3')
result.rows
=> [[3, 4]]

but in Topic is nothing

Topic.where(id: 3)
=> []

as you can see, finding is possible. But I have no idea of the Ruby syntax to delete exactly this one table entry.

Hmm. :thinking: It is unusual to be able to find it one way and not the other.

The rails console can be a bit of a sharp knife so it’d be best to figure out what exactly has gone wrong just to minimise any accidents/knock on effects.

How was this category deleted in the first place?

(Just in case the issue isn’t caused by this stray topic, I’ll throw in the basics of checking safe mode and seeing if there’s any more info about the error in your YourSite/logs page too)

Though I don’t know if your data is in a state where the category delete catch-all could help? Bulk delete all topics in a category

Good question. It was done some years ago by an other admin.

Meanwhile I deleted this topic direct in rails console with:

result = ActiveRecord::Base.lease_connection.exec_delete('DELETE FROM topics WHERE id = 3')

After this, topic is deleted :grinning_face:

1 Like

And that solved your wonky category link in the sidebar too?

It’s interesting that it’s only just showing a problem now when it had been happily deleted for a number of years.

If you figure out the connection let me know. :slight_smile:

1 Like

Unfortunately, this does not fix the error with the category link. But the problem with the non-deletable post is solved for now. The category problem is also not logged in the log. I will tackle this in the next few days.

1 Like