apache / apache/grails-core

GORM property implementing setter from abstract class does not get marked dirty

Open
#15,363 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

### Expected Behavior

That all properties, also those who implement an abstract setter, are marked dirty when the property changes.

### Actual Behaviour

If a property implements an abstract setter from an abstract class, then it is not marked dirty when changed.

### Steps To Reproduce

From the accached project's README:

## Issue description

When a domain class, extending from an abstract class, and this abstract class has `setFoo()` and getFoo() methods, and the domain class has a property `foo`, then the generated bytecode does not have a `markDirty` call for the property. Other properties not mentioned in the abstract class does have `markDirty` in the bytecode.

This behavior is not visible in Unit test, but in Integration test and production.

## Steps to reproduce

Run the test suite. One test `UsingAbstractIntegrationSpec` will fail.

To debug, add the debug compile options in `build.gradle` and run the test.

## Identified reason for this behavior

As far as I can tell, `org.grails.compiler.gorm.DirtyCheckingTransformer.addDirtyCheckingSetter()` is not calling `org.grails.compiler.gorm.DirtyCheckingTransformer.createMarkDirtyMethodCall` because in line #316 the `setter` node is not-null, as it is picked up from the abstract class.

I think it will be fixable just by adding a check for `setter == null || setter.isAbstrct()` in line #316, but since this is for GORM 8.1.2 (And Grails 6.2.3), I am not sure if 1) This is the right approach, and 2) If it is, how can I get it released?

### Environment Information

Ubuntu (but irrelevant)
Java 17
Grails 6.2.3 (I am about to add a branch that checks Grails 7 as well)

### Example Application

https://github.com/sbglasius/grails-gorm-abstract-setter-issue

### Version

6.2.3 and most likely 7.0.x as well

Contributor guide

Open the contributing guide

Research direction

Start in org.grails.compiler.gorm.DirtyCheckingTransformer, especially addDirtyCheckingSetter() and createMarkDirtyMethodCall(), and inspect the setter handling around line 316. Run the test suite and focus on UsingAbstractIntegrationSpec; done means abstract-setter properties receive markDirty behavior like other changed properties.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.