Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent enum behavior #789

Open
leviwilson opened this issue Dec 21, 2022 · 0 comments
Open

Inconsistent enum behavior #789

leviwilson opened this issue Dec 21, 2022 · 0 comments

Comments

@leviwilson
Copy link

leviwilson commented Dec 21, 2022

We have a model where the import behavior is inconsistent in populating an enum value with the INSERT INTO statement where sometimes it has it, and other times it does not.

Here is the model definition:

class SelectionField < Field
  after_initialize { |field| field.input_type = :selection }

  enum presentation: %i[dropdown multi_select radio_group]
end

If I try to import them directly in one context, you can see that rather than setting 0 for the enum it sets NULL (it doesn't make a difference if I choose a different value):

irb(main):001:0> Field.import!([field = SelectionField.new(presentation: 'dropdown')]); field.reload.presentation
2022-12-21 09:24:18.561745 D [11052:66460 (irb):1] (21.3ms) ActiveRecord -- Field Create Many -- {:sql=>"INSERT INTO \"fields\" (\"template_id\",\"row_index\",\"column_index\",\"column_width\",\"input_type\",\"character_limit\",\"is_required\",\"label\",\"default_value\",\"help_text\",\"mapping\",\"type\",\"presentation\",\"options\",\"custom_option\",\"columns\",\"styling\",\"size\",\"justification\",\"bold\",\"italics\",\"display_text\",\"past_date\",\"display_attributes\",\"created_at\",\"updated_at\",\"locking_group_id\",\"address_group_id\",\"repeating_element_id\",\"maximum_item_count\",\"hide_label\") VALUES (NULL,0,0,12,3,NULL,NULL,NULL,NULL,NULL,NULL,'SelectionField',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'2022-12-21 16:24:18.517471','2022-12-21 16:24:18.517471',NULL,NULL,NULL,NULL,FALSE) RETURNING \"id\"", :allocations=>4078, :cached=>nil}
2022-12-21 09:24:18.573973 D [11052:66460 core_ext.rb:77] (1.691ms) ActiveRecord -- SelectionField Load -- {:sql=>"SELECT \"fields\".\"id\", \"fields\".\"template_id\", \"fields\".\"row_index\", \"fields\".\"column_index\", \"fields\".\"column_width\", \"fields\".\"input_type\", \"fields\".\"character_limit\", \"fields\".\"is_required\", \"fields\".\"label\", \"fields\".\"default_value\", \"fields\".\"help_text\", \"fields\".\"mapping\", \"fields\".\"type\", \"fields\".\"presentation\", \"fields\".\"options\", \"fields\".\"custom_option\", \"fields\".\"columns\", \"fields\".\"styling\", \"fields\".\"size\", \"fields\".\"justification\", \"fields\".\"bold\", \"fields\".\"italics\", \"fields\".\"display_text\", \"fields\".\"past_date\", \"fields\".\"display_attributes\", \"fields\".\"created_at\", \"fields\".\"updated_at\", \"fields\".\"locking_group_id\", \"fields\".\"address_group_id\", \"fields\".\"repeating_element_id\", \"fields\".\"maximum_item_count\", \"fields\".\"hide_label\" FROM \"fields\" WHERE \"fields\".\"type\" = $1 AND \"fields\".\"id\" = $2 LIMIT $3", :binds=>{:type=>"SelectionField", :id=>"78471137-03d1-4202-a216-19594ac023bf", :limit=>1}, :allocations=>66, :cached=>nil}
=> nil

But in other contexts like doing a recursive: true it does get it

22-12-21 09:25:57.260591 D [11052:66460 (irb):4] (5.151ms) ActiveRecord -- InProgressTemplate Create Many -- {:sql=>"INSERT INTO \"templates\" (\"name\",\"status\",\"content_type_id\",\"type\",\"created_at\",\"updated_at\",\"form_image_id\",\"font_scale\",\"support_level\") VALUES ('got em',0,NULL,'InProgressTemplate','2022-12-21 16:25:57.254563','2022-12-21 16:25:57.254563',NULL,2,1) RETURNING \"id\"", :allocations=>59, :cached=>nil}
2022-12-21 09:25:57.267121 D [11052:66460 (irb):4] (3.332ms) ActiveRecord -- SelectionField Create Many -- {:sql=>"INSERT INTO \"fields\" (\"template_id\",\"row_index\",\"column_index\",\"column_width\",\"input_type\",\"character_limit\",\"is_required\",\"label\",\"default_value\",\"help_text\",\"mapping\",\"type\",\"presentation\",\"options\",\"custom_option\",\"columns\",\"styling\",\"size\",\"justification\",\"bold\",\"italics\",\"display_text\",\"past_date\",\"display_attributes\",\"created_at\",\"updated_at\",\"locking_group_id\",\"address_group_id\",\"repeating_element_id\",\"maximum_item_count\",\"hide_label\") VALUES ('dbd2fc0d-e977-4c02-855b-3fb38348e375',0,0,12,3,NULL,NULL,NULL,NULL,NULL,NULL,'SelectionField',0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'2022-12-21 16:25:57.262717','2022-12-21 16:25:57.262717',NULL,NULL,NULL,NULL,FALSE) RETURNING \"id\"", :allocations=>53, :cached=>nil}
2022-12-21 09:25:57.276695 D [11052:66460 (irb):4] (3.517ms) ActiveRecord -- LockingGroup Create Many -- {:sql=>"INSERT INTO \"locking_groups\" (\"row_index\",\"column_index\",\"column_width\",\"created_at\",\"updated_at\",\"template_id\") VALUES (0,0,12,'2022-12-21 16:25:57.272697','2022-12-21 16:25:57.272697','dbd2fc0d-e977-4c02-855b-3fb38348e375') RETURNING \"id\"", :allocations=>73, :cached=>nil}
2022-12-21 09:25:57.283543 D [11052:66460 (irb):4] (3.704ms) ActiveRecord -- SelectionField Create Many -- {:sql=>"INSERT INTO \"fields\" (\"template_id\",\"row_index\",\"column_index\",\"column_width\",\"input_type\",\"character_limit\",\"is_required\",\"label\",\"default_value\",\"help_text\",\"mapping\",\"type\",\"presentation\",\"options\",\"custom_option\",\"columns\",\"styling\",\"size\",\"justification\",\"bold\",\"italics\",\"display_text\",\"past_date\",\"display_attributes\",\"created_at\",\"updated_at\",\"locking_group_id\",\"address_group_id\",\"repeating_element_id\",\"maximum_item_count\",\"hide_label\") VALUES (NULL,0,0,12,3,NULL,NULL,NULL,NULL,NULL,NULL,'SelectionField',0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'2022-12-21 16:25:57.278858','2022-12-21 16:25:57.278858','9408f016-112c-4a32-8cee-ec8dc0bfecc4',NULL,NULL,NULL,FALSE) RETURNING \"id\"", :allocations=>53, :cached=>nil}
=> #<struct ActiveRecord::Import::Result failed_instances=[], num_inserts=1, ids=["dbd2fc0d-e977-4c02-855b-3fb38348e375"], results=[]>
irb(main):005:0> template.fields.map(&:presentation)
=> ["dropdown"]

Just trying to think through anything to try that might drive this behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant