Correctly use groups parameter only when its not empty

Fix #9745

Backport of c84c1f5 from master