houdiniproject/houdini

[BUG] Creating a new tag fails with HTTP 422

BenSturmfels opened this issue · 0 comments

We're looking to use tags to segment our supporters, but having some issues adding new tags.

When logged in on the main branch, I select an individual supporter, select "Edit tags", "Manage tags", enter a tag name and select "Add New Tag To List". This fires off an XHR request that fails with HTTP 422 Unprocessable Entity and the message "Sorry, could not process request" pops up at the bottom of the screen. Here's the relevant line from the log - not so helpful unfortunately:

method=POST path=/nonprofits/1/tag_definitions format=*/* controller=Nonprofits::TagDefinitionsController action=create status=422 duration=35.87 view=0.29 db=4.65 time=27893.52 exception= exception_object=

Here's the full console output from that request - again nothing very useful - just including for completeness.

* Locale set to 'en'
  User Load (0.3ms)  SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["id", 1], ["LIMIT", 1]]
  ↳ app/controllers/concerns/controllers/user/authorization.rb:71:in `administered_nonprofit'
   (0.4ms)  SELECT host_id FROM roles WHERE ("user_id" IN (1)) AND (roles.name IN ($Q$nonprofit_admin$Q$, $Q$nonprofit_associate$Q$))
  ↳ app/legacy_lib/query_roles.rb:19:in `host_ids'
  Nonprofit Load (0.3ms)  SELECT "nonprofits".* FROM "nonprofits" WHERE "nonprofits"."id" = $1 ORDER BY "nonprofits"."id" DESC LIMIT $2  [["id", 1], ["LIMIT", 1]]
  ↳ app/controllers/concerns/controllers/user/authorization.rb:73:in `administered_nonprofit'
  Nonprofit Load (0.3ms)  SELECT "nonprofits".* FROM "nonprofits" WHERE "nonprofits"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
  ↳ app/legacy_lib/fetch_nonprofit.rb:10:in `with_params'
   (0.5ms)  SELECT host_id FROM roles WHERE ("user_id" IN (1)) AND (roles.name IN ($Q$nonprofit_admin$Q$, $Q$nonprofit_associate$Q$))
  ↳ app/legacy_lib/query_roles.rb:19:in `host_ids'
  CACHE Nonprofit Load (0.0ms)  SELECT "nonprofits".* FROM "nonprofits" WHERE "nonprofits"."id" = $1 ORDER BY "nonprofits"."id" DESC LIMIT $2  [["id", 1], ["LIMIT", 1]]
  ↳ app/controllers/concerns/controllers/user/authorization.rb:73:in `administered_nonprofit'
  CACHE Nonprofit Load (0.0ms)  SELECT "nonprofits".* FROM "nonprofits" WHERE "nonprofits"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
  ↳ app/legacy_lib/fetch_nonprofit.rb:10:in `with_params'
   (0.6ms)  SELECT COUNT(roles) FROM roles WHERE (name IN ($Q$nonprofit_admin$Q$, $Q$nonprofit_associate$Q$)) AND ("user_id" IN (1)) AND ("host_id" IN (1))
  ↳ app/legacy_lib/query_roles.rb:11:in `user_has_role?'
   (0.6ms)  SELECT host_id FROM roles WHERE ("user_id" IN (1)) AND (roles.name IN ($Q$nonprofit_admin$Q$, $Q$nonprofit_associate$Q$))
  ↳ app/legacy_lib/query_roles.rb:19:in `host_ids'
  CACHE Nonprofit Load (0.0ms)  SELECT "nonprofits".* FROM "nonprofits" WHERE "nonprofits"."id" = $1 ORDER BY "nonprofits"."id" DESC LIMIT $2  [["id", 1], ["LIMIT", 1]]
  ↳ app/controllers/concerns/controllers/user/authorization.rb:73:in `administered_nonprofit'
  CACHE Nonprofit Load (0.0ms)  SELECT "nonprofits".* FROM "nonprofits" WHERE "nonprofits"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
  ↳ app/legacy_lib/fetch_nonprofit.rb:10:in `with_params'
  TRANSACTION (0.3ms)  BEGIN
  ↳ app/models/tag_definition.rb:32:in `no_dupes'
  TagDefinition Exists? (0.4ms)  SELECT 1 AS one FROM "tag_definitions" WHERE "tag_definitions"."nonprofit_id" = $1 AND ("tag_definitions"."deleted" = $2 OR "tag_definitions"."deleted" IS NULL) AND "tag_definitions"."name" IS NULL LIMIT $3  [["nonprofit_id", 1], ["deleted", false], ["LIMIT", 1]]
  ↳ app/models/tag_definition.rb:32:in `no_dupes'
  TRANSACTION (0.2ms)  ROLLBACK
  ↳ app/controllers/nonprofits/tag_definitions_controller.rb:23:in `create'
  TagDefinition Exists? (0.5ms)  SELECT 1 AS one FROM "tag_definitions" WHERE "tag_definitions"."nonprofit_id" = $1 AND ("tag_definitions"."deleted" = $2 OR "tag_definitions"."deleted" IS NULL) AND "tag_definitions"."name" IS NULL LIMIT $3  [["nonprofit_id", 1], ["deleted", false], ["LIMIT", 1]]
  ↳ app/models/tag_definition.rb:32:in `no_dupes'
method=POST path=/nonprofits/1/tag_definitions format=*/* controller=Nonprofits::TagDefinitionsController action=create status=422 duration=35.87 view=0.29 db=4.65 time=27893.52 exception= exception_object=
* Locale set to 'en'
  User Load (0.5ms)  SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["id", 1], ["LIMIT", 1]]
  ↳ app/controllers/concerns/controllers/user/authorization.rb:71:in `administered_nonprofit'
   (0.5ms)  SELECT host_id FROM roles WHERE ("user_id" IN (1)) AND (roles.name IN ($Q$nonprofit_admin$Q$, $Q$nonprofit_associate$Q$))
  ↳ app/legacy_lib/query_roles.rb:19:in `host_ids'
  Nonprofit Load (0.3ms)  SELECT "nonprofits".* FROM "nonprofits" WHERE "nonprofits"."id" = $1 ORDER BY "nonprofits"."id" DESC LIMIT $2  [["id", 1], ["LIMIT", 1]]
  ↳ app/controllers/concerns/controllers/user/authorization.rb:73:in `administered_nonprofit'
  Nonprofit Load (0.3ms)  SELECT "nonprofits".* FROM "nonprofits" WHERE "nonprofits"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
  ↳ app/legacy_lib/fetch_nonprofit.rb:10:in `with_params'
   (0.6ms)  SELECT host_id FROM roles WHERE ("user_id" IN (1)) AND (roles.name IN ($Q$nonprofit_admin$Q$, $Q$nonprofit_associate$Q$))
  ↳ app/legacy_lib/query_roles.rb:19:in `host_ids'
  CACHE Nonprofit Load (0.0ms)  SELECT "nonprofits".* FROM "nonprofits" WHERE "nonprofits"."id" = $1 ORDER BY "nonprofits"."id" DESC LIMIT $2  [["id", 1], ["LIMIT", 1]]
  ↳ app/controllers/concerns/controllers/user/authorization.rb:73:in `administered_nonprofit'
  CACHE Nonprofit Load (0.0ms)  SELECT "nonprofits".* FROM "nonprofits" WHERE "nonprofits"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
  ↳ app/legacy_lib/fetch_nonprofit.rb:10:in `with_params'
   (0.6ms)  SELECT COUNT(roles) FROM roles WHERE (name IN ($Q$nonprofit_admin$Q$, $Q$nonprofit_associate$Q$)) AND ("user_id" IN (1)) AND ("host_id" IN (1))
  ↳ app/legacy_lib/query_roles.rb:11:in `user_has_role?'
   (0.5ms)  SELECT host_id FROM roles WHERE ("user_id" IN (1)) AND (roles.name IN ($Q$nonprofit_admin$Q$, $Q$nonprofit_associate$Q$))
  ↳ app/legacy_lib/query_roles.rb:19:in `host_ids'
  CACHE Nonprofit Load (0.0ms)  SELECT "nonprofits".* FROM "nonprofits" WHERE "nonprofits"."id" = $1 ORDER BY "nonprofits"."id" DESC LIMIT $2  [["id", 1], ["LIMIT", 1]]
  ↳ app/controllers/concerns/controllers/user/authorization.rb:73:in `administered_nonprofit'
  CACHE Nonprofit Load (0.0ms)  SELECT "nonprofits".* FROM "nonprofits" WHERE "nonprofits"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
  ↳ app/legacy_lib/fetch_nonprofit.rb:10:in `with_params'
   (0.6ms)  SELECT id, name, created_at FROM tag_definitions WHERE (tag_definitions.nonprofit_id = 1) AND (coalesce(deleted, FALSE) = FALSE)
  ↳ app/controllers/nonprofits/tag_definitions_controller.rb:19:in `index'
method=GET path=/nonprofits/1/tag_definitions format=json controller=Nonprofits::TagDefinitionsController action=index status=200 duration=29.41 view=0.35 db=4.06 time=27893.58 exception= exception_object=