GLM-5.3 Flash · Balanced
feature-can-edit-category-host-relationships-for-embedding-discourse-cursor
Discourse · Ruby · M · 100–299 lines · 6 files
The normal review, with one generalist agent. Judge: Claude Opus 5.5.
- Gold bugs found
- 5 of 10
- Comments published
- 7
- Comments matching a bug
- 5
- Comments not matching
- 2
- Cost of this PR
- $0.086
Published comments (7)
Migration crashes when embed_category setting is missing or invalid — Any site without a stored `embed_category` value gets a crash in `db:migrate` and a blocked upgrade, even though the empty case was meant to fall through to `uncategorized_category_id`. Nil-check the row before reading `['id']`, and guard the fallback lookup the same way.
Migrated hosts stored without stripping scheme/path break record_for_host matching — Hosts stored with a scheme or path, like `http://discourse.org`, never match the `uri.host` comparison in `record_for_host`, so previously-working embedding silently stops. Apply the same scheme/path stripping to `h` before inserting.
Migration interpolates unquoted host value into SQL, allowing injection — A single quote in any stored host value breaks or hijacks the insert run during migrate. Build the `VALUES` clause with `ActiveRecord::Base.connection.quote(h)` or a parameterized insert instead of interpolating `h` raw.
update and destroy raise NoMethodError on missing host instead of 404 — A stale or double-deleted id makes `host` nil, so `save_host(host)` and `host.destroy` raise NoMethodError and return a 500 instead of a 404. Raise `Discourse::NotFound` when the lookup misses.
NoMethodError in before_validation when host is nil — Saving a record without a `host` crashes in the `before_validation` hook before `validates_format_of` can reject it, yielding a 500 instead of a 422. Guard both `sub!` calls with a presence check on `self.host`.
record_for_host ignores ports on stored hosts, so ported hosts never match — The validation regex accepts `example.com:8080`, but `record_for_host` compares it against the portless `uri.host`, so such records can never match a referer. Strip the port when comparing, or match host and port explicitly.
Delete action swallows destroyRecord failures (no .catch) — A failed deletion leaves the row stuck in the table with an unhandled rejection and no error shown, unlike `save()` in this component. Chain `.catch(popupAjaxError)` onto the `destroyRecord()` promise.