Object saved to variable throws RecordInvalid for data_option


  • Used Zammad version: 5.0
  • Used Zammad installation type: (source, package, docker-compose, …) package
  • Operating system: Ubuntu 18.04
  • Browser + version: Firefox/Chrome newest on both

Expected behavior:

  • creating an object and saving it to a variable ( object1 = ObjectManager::Attribute.create ) and setting all necessary paramaters ( object1.screens, object.data_option…) should generated a new Object after using object.save!

Actual behavior:

  • using a variable throws an ActiveRecord::RecordInvalid error because object1.data_option = { :type => “text”, :maxlength => 120, :null => true } both :type and :maxlength are allegedly not set.

Steps to reproduce the behavior:

  1. object1 = ObjectManager::Attribute.create
  2. Set parameters (object1.data_options, object1.screens etc)
  3. using object1.save! throws the error mentioned before

If you don’t use a variable and just do ObjectManager::Attribute.create(data_options: …).save! it works just fine. Also if you duplicate an existing Object to a variable and save that variable it works fine.

Dunno if that is intended and I’m just not seeing it.

Also e.g if you create a User Object via console it doesn’t get added to the user table within the postgres Database. Even after Cache.clear und restarting zammad I still have to add the new User Objects manually as a new column in the user table.

Sorry but I can’t really follow what you’re trying to do with the supplied information.
What I can see from what you’ve wrote that both approaches don’t make too much sense in my opinion.

If you want to write information of the created object into a variable that technically is possible, but requires you to create the object in one step and not several.

Also create combined with save at the end makes technically no sense at all.
You may want to stick to using the UI do add objects to rule out human error.

Please don’t get me wrong, I’m just trying to keep your instance in a working state here.

Greetings, sorry for the late response - I did not expect to get an answer so I stopped checking after some time.

First: yes using save and create in one step is redundant I must have forgotten to delete it back then when I created the topic.

Second: Rereading my explanation I described my Issue terribly, sorry for that. But as it seems you still managed to answer my question.

to clarify and recap:

At the end all I wanted to know is when I create an object and save it to a variable

Object1 = ObjectManager::Attribute.create

and then later use that variable to set the necessary parameter

and Object1.data_options

Rails throws RecordInvalid error because apparently the keys :maxlength and :type within data_option are not set even though they are.
I just was curious if this was intended because I never ran into this error while creating e.g Triggers / Groups etc. while doing the exact same.
But if you say that its simply not possible to use several steps then it works as intended (I mean I knew that I could create it with just one step but as I said I was curious why I receive an error if i simply want to create it with more steps)

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.