You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Exception:
Could not grant action 1 on object AccessControl::SomePolicy with id 4 for actor #Role:0x00007fa8f1f5bad0 because PG::InFailedSqlTransaction: ERROR: current transaction is aborted, commands ignored until end of transaction block
raiseAccessly::GrantError.new("Could not grant action #{action_id} on object #{object_type} for actor #{@actor} because #{e}")
But is occurring after
rescue ActiveRecord::RecordNotUnique
nil
is encountered which basically hides the actual error.
Try to grant! new permission within transaction
Permission record already exists which is rescued by rescue ActiveRecord::RecordNotUnique and returns nil
Transaction then fails and returns the secondary exception message: "Could not grant action 1 on object AccessControl::SomePolicy with id 4"
Underlying issue
The problem is that we're encountering an exception within a transaction which fails the transaction but is being silenced by the return of nil
Potential options
I know it is trying to avoid the lookup of db records here but something like an upsert could be a better option instead of rescuing ActiveRecord::RecordNotUnique and silencing the error
We could first check to see if the record exists with a find_by and then branch to create! if it doesn't or simply return nil without an rescuing a RecordNotUnique exception
We could use find_or_create_by! kinda like upsert
The text was updated successfully, but these errors were encountered:
joshmfrankel
changed the title
When calling grant! for records that already have permissions inside of transactions there is no exception message
When calling grant! for records that already have permissions inside of transactions the transaction fails without an exception message
Sep 10, 2019
Sample code to reproduce issue
Exception:
Could not grant action 1 on object AccessControl::SomePolicy with id 4 for actor #Role:0x00007fa8f1f5bad0 because PG::InFailedSqlTransaction: ERROR: current transaction is aborted, commands ignored until end of transaction block
This exception is raised here:
accessly/lib/accessly/permission/grant.rb
Line 75 in 1a477f9
But is occurring after
is encountered which basically hides the actual error.
Underlying issue
The problem is that we're encountering an exception within a transaction which fails the transaction but is being silenced by the return of nil
Potential options
find_by
and then branch to create! if it doesn't or simply return nil without an rescuing a RecordNotUnique exceptionfind_or_create_by!
kinda like upsertThe text was updated successfully, but these errors were encountered: