8000 run update_resource inside a transaction to avoid autosaving relation… · activeadmin/activeadmin@a12c203 · GitHub
[go: up one dir, main page]

Skip to content

Commit a12c203

Browse files
javierjuliomgrunberg
authored andcommitted
run update_resource inside a transaction to avoid autosaving relationships through assign_attributes when the record is invalid
1 parent 0ed19fc commit a12c203

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

app/controllers/active_admin/resource_controller/data_access.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,16 @@ def save_resource(object)
168168
#
169169
# @return [void]
170170
def update_resource(object, attributes)
171-
object = assign_attributes(object, attributes)
171+
status = nil
172+
ActiveRecord::Base.transaction do
173+
object = assign_attributes(object, attributes)
172174

173-
run_update_callbacks object do
174-
save_resource(object)
175+
run_update_callbacks object do
176+
status = save_resource(object)
177+
raise ActiveRecord::Rollback unless status
178+
end
175179
end
180+
status
176181
end
177182

178183
# Destroys an object from the database and calls appropriate callbacks.

0 commit comments

Comments
 (0)
0