Data Explorer bug when querying user_histories topic_id

I don’t have a lot of experience using Data Explorer, so this might be due to my lack of understanding, but I’ve noticed that this query gives me a 500 error:

FROM user_histories uh
where = 6290

ActiveModel::MissingAttributeError (missing attribute: category_id) /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activemodel-6.0.1/lib/active_model/attribute.rb:221:in `value’

If I run the DB from the container I can see that uh.topic_id is 1391 (i.e. non-NULL). Basically, I changed the category of topic 1391.

What I don’t understand is why this is giving me an error. I suspect it has something to do with the topic_id to topic conversion that Data Explorer does (maybe it needs the category_id to do this, but this isn’t available?)

Is this a legitimate bug or am I missing something?

How was this done? Does loading that topic in the UI work correctly?

1 Like

I changed it via de UI and yes, it works correctly when I go to the corresponding URL.

By the way, I had a typo in my original post, I wrote 1381 the second time, but I also meant 1391. Although, the number is not important because it happens with multiple topics, not just this one.

When you run the database query from the console, what is the value of the action that is returned? It should be set to an integer. Knowing what value is returned might make it possible for us to recreate the issue.

Action 47: notified_about_get_a_room

1 Like

I don’t know if it’s a related bug, but I also get a 500 error when I run this query in the Data Explorer:

select topic_id from posts limit 10

When I check the logs I see this:

ActiveModel::MissingAttributeError (missing attribute: category_id) /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activemodel-6.0.1/lib/active_model/attribute.rb:221:in `value'

I have no problem running it from the container:

discourse=# select topic_id from posts limit 10;
(10 rows)

I assume the problem is that rendering a topic also requires selecting the category_id of a model that doesn’t have this attribute. Can anyone reproduce this issue?


This does not sound right @techAPJ can you investigate? select topic_id from posts limit 10 should work in data explorer.


This would be triggering the fancy render codepath which is trying to deliver the topic title and slug to the client in the results.