User data archive export fails: undefined method 'url' for an instance of DiscourseDataExplorer::QueryGroup

AI-generated summary

one1 reported a bug where user data archive exports fail for users who have bookmarked a Data Explorer group report. The issue occurs during the Jobs::ExportUserArchive background job, specifically when generating the Bookmarks CSV. The job crashes because it attempts to call the .url method on the bookmarked object, but the DiscourseDataExplorer::QueryGroup model does not implement this method. This results in a NoMethodError: undefined method 'url' for an instance of DiscourseDataExplorer::QueryGroup.

The report includes reproduction steps: creating a Data Explorer query, bookmarking it as a group report, and then attempting to request a user data archive. The crash prevents the export from completing, so no download link is sent. one1 analyzed the root cause, noting that while bookmarks are polymorphic and the export expects a url method for core types like Topic and Post, the Data Explorer plugin’s QueryGroup type lacks it. Suggested fixes included implementing the url method in the plugin or adding defensive checks in the core export job (e.g., using respond_to?(:url)).

A temporary workaround involved manually deleting the offending bookmarks from the database where bookmarkable_type was set to 'DiscourseDataExplorer::QueryGroup'. meta-bot confirmed that the issue has been resolved in pull request #46916, which ensures that user archive exports now correctly generate valid links for bookmarked Data Explorer reports.

Full Disclosure: I used ask.discourse to compose this bug report after a conversation. Also, I know I’m behind on updates but I wanted to post this while it was still fresh in my mind.

I was able to reproduce this on two different user accounts.

Summary

Requesting a user data archive (Preferences → Export your data → Request archive) fails for users who have bookmarked a Data Explorer group report. The Jobs::ExportUserArchive background job crashes while generating the Bookmarks CSV, so the export never completes and no download link is sent.

Environment

  • Discourse version: 2026.8.0-latest.1
  • Data Explorer: bundled with core (version follows core)
  • Self-hosted / hosted: self-hosted
  • Ruby/Rails stack per backtrace: activemodel/activerecord 8.0.5.1, Sidekiq 7.3.10

Steps to reproduce

  1. As an admin, create a Data Explorer query and grant access to a group.
  2. On the group’s Reports tab, click Bookmark on the query so it becomes a bookmarked group report.
  3. As that same user, go to Preferences → Export your data → Request archive.
  4. Watch the job fail (check Admin → Logs or Sidekiq logs).

Expected behavior

The user archive should be generated and the user should receive the download link, including their bookmarks.

Actual behavior

The export job raises an exception and the archive fails. The backtrace shows the crash occurring in bookmarks_export, where the job calls .url on the bookmarked object:

Job exception: undefined method 'url' for an instance of DiscourseDataExplorer::QueryGroup

Backtrace (abridged to the relevant frames):

activemodel-8.0.5.1/lib/active_model/attribute_methods.rb:512:in 'ActiveModel::AttributeMethods#method_missing'
activerecord-8.0.5.1/lib/active_record/attribute_methods.rb:495:in 'ActiveRecord::AttributeMethods#method_missing'
/var/www/discourse/app/jobs/regular/export_user_archive.rb:325:in 'block in Jobs::ExportUserArchive#bookmarks_export'
activerecord-8.0.5.1/lib/active_record/relation/delegation.rb:101:in 'Array#each'
activerecord-8.0.5.1/lib/active_record/relation/delegation.rb:101:in 'ActiveRecord::Delegation#each'
/var/www/discourse/app/jobs/regular/export_user_archive.rb:319:in 'Jobs::ExportUserArchive#bookmarks_export'
/var/www/discourse/app/jobs/regular/export_user_archive.rb:170:in 'Kernel#public_send'
/var/www/discourse/app/jobs/regular/export_user_archive.rb:170:in 'block (2 levels) in Jobs::ExportUserArchive#execute'
/var/www/discourse/app/jobs/regular/export_user_archive.rb:168:in 'block in Jobs::ExportUserArchive#execute'

Analysis

Bookmarks are polymorphic. The export job calls bookmarkable.url, which works for core bookmarkable types (Topic, Post), but DiscourseDataExplorer::QueryGroup does not implement url, so the job raises NoMethodError on the first such bookmark.

It appears Data Explorer registers query groups as bookmarkable (via the group report Bookmark button), but the model lacks the url method (or the core export job needs a guard for bookmarkable types that don’t provide one).

Suggested fix

Either implement a url method on DiscourseDataExplorer::QueryGroup, or make core’s bookmarks_export defensive (e.g., bookmarkable.respond_to?(:url) / rescue per-row) so a single unsupported bookmarkable type can’t kill the whole export.

Workaround

Deleting the offending bookmarks (rows in bookmarks where bookmarkable_type = 'DiscourseDataExplorer::QueryGroup' for the affected user) allows the export to complete.

1 Like

Fixed in #46916. User archive exports now generate a valid link for bookmarked Data Explorer reports.

3 Likes