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

Bug: removeAll(User u) in UserRole empties whole table #628

Open
2 of 4 tasks
feuernurmitm opened this issue Mar 18, 2021 · 1 comment
Open
2 of 4 tasks

Bug: removeAll(User u) in UserRole empties whole table #628

feuernurmitm opened this issue Mar 18, 2021 · 1 comment

Comments

@feuernurmitm
Copy link

feuernurmitm commented Mar 18, 2021

Task List

  • Steps to reproduce provided
  • Stacktrace (if present) provided
  • Example that reproduces the problem uploaded to Github
  • Full description of the issue provided (see below)

Steps to Reproduce

  1. Create a new Grails 4.X application
  2. add compile 'org.grails.plugins:spring-security-core:4.0.3' to build.gradle
  3. run grailsw s2-quickstart myapp User Role
  4. create at least one role and two users, e.g. in Bootstrap.groovy:
    Role role = new Role(authority: 'ADMIN').save(); User user1 = new User(username: 'user1', password: 'abc123').save(); User user2 = new User(username: 'user2', password: 'abc123').save();
  5. Attach users to roles: UserRole.create(user1, role, true); UserRole.create(user2, role, true)
  6. Call UserRole.removeAll(user1) from anywhere, e.g. TestController.groovy:
    User user = User.findByUsername('user1'); UserRole.removeAll(user); user.delete()

Expected Behaviour

To my understanding UserRole.removeAll(User u) {...} should remove every UserRole entry connected to the user u.

Actual Behaviour

Instead of just one entry being deleted, the method deletes all UserRole entries in the database.

This caught my attention in the GORM for Hibernate docs:

Note that one limitation with regards to batch operations is that join queries (queries that query associations) are not allowed.

Environment Information

  • Operating System: Windows 10
  • GORM Version: 7.0.8.RELEASE
  • Grails Version (if using Grails): 4.0.6
  • JDK Version: 11

Example Application

  • TODO: link to Github repository with example that reproduces the issue
  • I will provide one, if necessary :)
@logantracyo
Copy link

This appears to be similar to the problem mentioned in this S2UI issue, which includes an example.

I ran into that same problem, and in the course of investigating it, discovered a workaround: Copy the plugin method to a new class extending the plugin's class -- for some reason, with no code changes, just that override makes it work as expected, deleting only the intended UserRole(s).

In case that workaround helps anyone else (including perhaps shedding some light on the cause of the problem), full details are in this comment on that S2UI issue.

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

2 participants