Rails Console changes not persistent in Docker-Compose


  • Used Zammad version: 3.2
  • Used Zammad installation source: Docker-Compose
  • Operating system: Debian 10
  • Browser + version: Rails Console

Expected behavior:

  • I have been writing a ruby script to assist our migration from OTRS (So that when I import the last OTRS diff I can run the script to set up our groups and roles and user permissions)
  • I expect for any user changes or changes to groups and roles to persist, e.g:
me = User.find_by(email:"my@email.com")
  • After this I reindex elasticsearch.

Actual behavior:

  • I run this command and it works temporarily, but after about 5 minutes the scheduler container performs some searchindex jobs and changes everything back completely.
  • I also destroyed some groups and they reappeared after the same period.
  • Even if I stop the scheduler container, make changes and finally reindex elasticsearch before starting the scheduler again, as soon as the scheduler starts it will erase my changes. How can I avoid this?

Steps to reproduce the behavior:

  • Apart from installing via Docker-Compose, and making some user or group changes, I’m not sure.

Potential cause:
OTRS Diff might still be running, I’ll have to check when I get back home tonight. sigh

You’re simply not saving your changes, that’s why the changes are not permanent. In fact the above change only applies to that one rails console session, not Zammad itself.

me.save! will do the trick.

Thanks for the suggestion, what confuses me now is that there was a diff running (unsure why); I turned it off and all changes seem to be persistent now, without requiring a .save!. Is this expected? Will my changes revert without this .save! call? If so, when will they revert?

The information stored and changed in me variable will be consistent during the console runtime. It will be cleared after. So if you call me the object information being returned is always the value you modified it to.

me.save! actually submits these changes to the database which makes it persistent.

You can cross check that by updating me with any value you want and then run the rails command (e.g. for finding the user you updated) without using the me variable. You should see the differences then. :slight_smile:

If you do not me.save! your changes, as soon as you close the console session, the variable is being freed / destroyed and thus your changes are lost.

You should also be able to cross check this via the ui by the way. If you update the note without .save!, you shouldn’t see it in the web interface (no matter how hard and often you hit “refresh”).

I think I understand, but I am a bit confused. You said that loading a user into a variable me as follows:

me = User.find_by(login: "my@email.com")
me.update_attributes(login: "me")

will not update the web interface. However, it seems that just did change the interface?? I was able to login with my usual password and “me” as the username.

that’s odd. If it lives in the UI, it should also be persistent.

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