GLM-5.3 · 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 Haiku 5.5.
- Gold bugs found
- 2 of 4
- Comments published
- 6
- Comments matching a bug
- 2
- Comments not matching
- 4
- Cost of this PR
- $1.544
Published comments (6)
Migration crashes with NoMethodError when no 'embed_category' setting row exists — On any site without an `embed_category` row, `[0]` returns nil and `nil['id']` aborts `db:migrate` before the `uncategorized_category_id` fallback can run. Guard the query result as migration 20140929204155 does, checking `cmd_tuples > 0` before indexing.
Migration inserts unnormalized hosts, breaking exact-host matching for scheme/path-qualified entries — Migrated rows like `https://example.com/1234` are stored verbatim, so `record_for_host`'s exact `lower(host) = uri.host` match fails and previously-allowed hosts get `Discourse::InvalidAccess` on `/embed/comments`. Apply the model's normalization, stripping the scheme and path, to each line before inserting.
Unescaped host value interpolated into INSERT breaks migration on quotes — A single quote in an old setting value produces invalid SQL and aborts `db:migrate` mid-run. Escape `h` with `PG::Connection.escape_string` as sibling migration 20140929204155 does, or use bound `exec_insert`.
Hosts saved with a port never match in record_for_host, rejecting valid embed requests — A host saved as `example.com:8080` passes the validation regex but is stored with the port, which `uri.host` never includes, so `record_for_host` rejects every embed request from it. Strip the port in `before_validation` with `sub!(/:\d+$/, '')` or compare including it in `record_for_host`.
Update and destroy raise NoMethodError on stale embeddable host id — A stale id makes `save_host(nil)` call `nil.host=` and `destroy` call `nil.destroy`, returning a 500 instead of a 404. Add `raise Discourse::NotFound` when the `EmbeddableHost.where(id: params[:id]).first` lookup is nil.
before_validation callback raises NoMethodError when host is nil — Guard with `self.host = (self.host || '').sub(...)`.