Tenant Id field skips validation when the domain implements MultiTenant
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
### Task List
- [x] Steps to reproduce provided
- [x] Stacktrace (if present) provided (Not required)
- [x] Example that reproduces the problem uploaded to Github
- [x] Full description of the issue provided (see below)
### Steps to Reproduce
1. Run CustomerSpec.groovy
2. Note the Customer domain class includes a Long firmId field with a non-nullable constraint.
3. Note the Customer domain class implements MuiltiTenant and a mapping for the tenantId to the firmId field.
### Expected Behaviour
Running the test will attempt to save an instance of the Customer class without setting the mandatory firmId field. This should throw a validation exception.
### Actual Behaviour
A ValidationException is not thrown. On inspection via a debugger, we can see in the Gorm DefaultConstraintEvaluator, the firmId field is considered a 'derived' property and as a result is removed from the list of properties to be constrained. Therefore validation never takes place.
### Environment Information
- **Operating System**: Windows
- **GORM Version:** 7.2.1
- **Grails Version (if using Grails):** 5.1.7
- **JDK Version:** 8
### Example Application
- https://github.com/davebrown1975/grails_multitenant_validation
Contributor guide
Research direction
Start by running CustomerSpec.groovy in the linked example application to reproduce the missing ValidationException. Read GORM's DefaultConstraintEvaluator where firmId is classified as a derived property and removed from constrained properties; done means an unset non-nullable firmId on the MultiTenant Customer triggers validation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100