codeconsole commented on code in PR #16136:
URL: https://github.com/apache/grails-core/pull/16136#discussion_r3797724748
##########
grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/config/AbstractGormMappingFactory.java:
##########
@@ -178,25 +181,47 @@ protected IdentityMapping getIdentityMappedForm(final
ClassMapping classMapping,
public T createMappedForm(PersistentProperty mpp) {
Map<String, T> properties = entityToPropertyMap.get(mpp.getOwner());
if (properties != null && properties.containsKey(mpp.getName())) {
- return properties.get(mpp.getName());
+ T property = properties.get(mpp.getName());
+ if (!isIdentityOrVersion(mpp) && !property.isNullableConfigured())
{
+ property.setNullable(defaultNullable);
+ }
+ return property;
}
else if (properties != null) {
- Property property = properties.get(IDENTITY_PROPERTY);
+ T property = properties.get(IDENTITY_PROPERTY);
if (property != null && mpp.getName().equals(property.getName())) {
- return (T) property;
+ return property;
}
}
T defaultMapping = properties != null ? properties.get("*") : null;
if (defaultMapping != null) {
try {
- return (T) defaultMapping.clone();
+ T property = (T) defaultMapping.clone();
+ if (!isIdentityOrVersion(mpp) &&
!property.isNullableConfigured()) {
+ property.setNullable(defaultNullable);
+ }
+ return property;
} catch (CloneNotSupportedException e) {
- return BeanUtils.instantiateClass(getPropertyMappedFormType());
+ T property =
BeanUtils.instantiateClass(getPropertyMappedFormType());
+ if (!isIdentityOrVersion(mpp)) {
+ property.setNullable(defaultNullable);
+ }
+ return property;
}
}
else {
- return BeanUtils.instantiateClass(getPropertyMappedFormType());
+ T property =
BeanUtils.instantiateClass(getPropertyMappedFormType());
+ if (!GormProperties.IDENTITY.equals(mpp.getName()) &&
+ !GormProperties.VERSION.equals(mpp.getName())) {
Review Comment:
Nit: the only one of four branches still inlining this guard — the others
(:185, :201, :207) call the helper at :223. Same behavior today, but widening
the exclusion later would silently miss this one.
```suggestion
if (!isIdentityOrVersion(mpp)) {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]