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
frominvenio_accessimportaction_factory, ActionRolesfrominvenio_accounts.modelsimportRolefrominvenio_dbimportdbimportrandomrandom_role=random.choice(Role.query.all())
action=action_factory('my-action')
action_arg=action_factory('my-action-arg', parameter=True)
foriinrange(3):
db.session.add(ActionRoles.allow(action, role=random_role))
db.session.commit()
foriinrange(3):
try:
db.session.add(ActionRoles.allow(action_arg('argValue'), role=random_role))
db.session.commit()
exceptExceptionase:
print('Error', str(e)) # You should see 2 SQLAlchemy errors
access_actionroles table after the script
Expected behavior
The UniqueConstraint key should be respected even if action doesn't have any argument.
Regarding this StackOverflow answer, it should be possible using 2 indexes (one if argument is null, second if argument is not null) : https://stackoverflow.com/a/57647018
Additional context
It should be the same for ActionUsers and ActionSystemRoles
The text was updated successfully, but these errors were encountered:
Package version (if known):
1.4.2
Describe the bug
It is possible to register multiple
ActionRoles
with same values despite the SQLAlchemyUniqueConstraint
(https://github.com/inveniosoftware/invenio-access/blob/master/invenio_access/models.py#L115-L118) ifargument
is None.Steps to Reproduce
access_actionsroles table initial state
access_actionroles table after the script
Expected behavior
The
UniqueConstraint
key should be respected even if action doesn't have any argument.Regarding this StackOverflow answer, it should be possible using 2 indexes (one if argument is null, second if argument is not null) : https://stackoverflow.com/a/57647018
Additional context
It should be the same for
ActionUsers
andActionSystemRoles
The text was updated successfully, but these errors were encountered: