Rails 5.0.2 issue with Enum Types

Hi,

I’ve been investigating an issue we’ve experienced the last few weeks since upgrading to Rails 5 and was hoping to see if anyone had an insight.

Issue:

Every so often after our Rails server starts our API will return null for one enum on one model even though the enum’s backing field is non-null in the database. Restarting the Rails server fixes the issue.

Setup:

Heroku + PostGres

ruby 2.4.1

rails 5.0.2

puma 3.9.0

(any many other gems)

I’ve tried reproducing this locally by running a script to start and stop the rails server to see if that would reproduce it, but found nothing after several hours.

Reading through the enum.rb module it looks like this could happen if the EnumType @mapping variable was empty, but I don’t see how that would happen in practice, as it should be initialized when the enum is defined when loading all the ActiveRecord models.

Any ideas?