Creating a new ticket state via ruby console fails whit a NotNullViolation

  • Used Zammad version: 5.1.x
  • Used Zammad installation type: package
  • Operating system: ubuntu 20.04 lts

Expected behavior:

according to Working with ticket information — Zammad documentation i should be able to add a new ticket state. I used the Non-Pending states script

name: ‘Developing’,
state_type: Ticket::StateType.find_by(name: ‘open’),
created_by_id: 1,
updated_by_id: 1,

Actual behavior:

I’ve tried two variants. First I only changed the value ‘open’ on line 3 of the script. Second I tried to change ‘open’ on line 3 and ‘Developing’ on line 2.

irb(main):001:1* Ticket::State.create_or_update(
irb(main):002:1* id: 8,
irb(main):003:1* name: ‘Bearbeitung’,
irb(main):004:1* state_type: Ticket::StateType.find_by(name: ‘Bearbeitung’),
irb(main):005:1* created_by_id: 1,)

Both variants failed with the following error:

Traceback (most recent call last):
2: from (irb):1
1: from app/models/application_model/can_creates_and_updates.rb:45:in `create_or_update’
ActiveRecord::NotNullViolation (PG::NotNullViolation: ERROR: null value in column “state_type_id” violates not-null constraint)
DETAIL: Failing row contains (16, null, Bearbeitung, null, f, f, f, null, t, 1, 1, 2022-03-23 09:03:13.577, 2022-03-23 09:03:13.577).

state_type_id (second value in the DETAIL line) can’t be null in table ticket_states. it’s referencing to table ticket_state_types. So the script should probably create an entry in ticket_state_types first and then create the entry in ticket_states. The tables seem kind of redundant.

What am I doing wrong?

Thanks for your help


Well there’s no statetype “Bearbeitung” so your commands have to fail.
Our documentation has you covered: Working with ticket information — Zammad documentation

As this is possibly not enough context for you to understand, please also have a look at the state documentation on our user documentation: State — Zammad (for Agents) documentation