The GitHub Actions job "CodeQL" on 
grails-core.git/feature/mongo-domain-mapping-context-backoff has succeeded.
Run started by GitHub user codeconsole (triggered by codeconsole).

Head commit for run:
5b21e914519454feb441fe7e0298ff22c575c756 / Scott Murphy Heiberg 
<[email protected]>
Defer grailsDomainClassMappingContext to GORM-MongoDB instead of overriding

Turns the grailsDomainClassMappingContext bean-definition override into a clean
back-off using stock 8.0.x auto-configuration ordering, scoped to MongoDB.

grails-core (behaviour-neutral on its own):
  GrailsDomainClassAutoConfiguration.grailsDomainClassMappingContext is now
  @ConditionalOnMissingBean(name = 'grailsDomainClassMappingContext'). The 
condition is
  evaluated by ConfigurationClassPostProcessor, before 
GrailsApplicationPostProcessor runs
  any doWithSpring, so with no datastore the fallback still registers exactly 
as before.

grails-data-mongodb:
  - MongoMappingContextAutoConfiguration registers the MongoMappingContext as
    'mongoMappingContext' with the 'grailsDomainClassMappingContext' alias, 
ordered
    beforeName GrailsDomainClassAutoConfiguration, so the framework fallback 
backs off. It
    builds the context via MongoDatastore.createMappingContext(config, classes) 
so it is
    identical (settings + validation registry) to the one the datastore would 
build.
  - It engages only when MongoDB is the primary datastore
    (@ConditionalOnMissingClass org.grails.orm.hibernate.HibernateDatastore), 
mirroring
    MongodbGrailsPlugin.setSecondaryDatastore(hasHibernatePlugin()): when 
Hibernate is
    present MongoDB is secondary, must not own grailsDomainClassMappingContext, 
and the
    initializer keeps its legacy path.
  - MongoDatastore.createMappingContext(PropertyResolver, Class...) is now 
public so the
    auto-configuration can build the same context the datastore uses.
  - MongoDbDataStoreSpringInitializer detects a pre-registered 
'mongoMappingContext' and
    builds mongoDatastore around it (new MongoDatastore(config, 
connectionSourceFactory,
    mappingContext, publisher) for the default path; the existing 
MongoDatastore(client,
    config, mappingContext, publisher) for the supplied-client path) instead of
    re-registering its own. A single context is shared and nothing is 
overridden.
    Standalone (non-Grails) bootstrap is unchanged; secondary datastores keep 
their path.
  - Adds the MongoDatastore(PropertyResolver, MongoConnectionSourceFactory,
    MongoMappingContext, ConfigurableApplicationEventPublisher) constructor.

Verified against a MongoDB testcontainer 
(MongoDbDataStoreSpringInitializerSpec): the
datastore reuses a pre-registered context (identity), the bean is not 
overridden, the
alias resolves to the same instance, and an entity round-trips. Existing 
standalone tests
(custom codecs, custom type marshallers, primary/secondary alias, 
geo/constraints) still
pass.

Remaining (best as a grails-plugin app-slice test): assert 
MongoMappingContextAutoConfiguration
ordering makes GrailsDomainClassAutoConfiguration's fallback back off in a real 
Boot context,
and confirm connection-source-factory-autowired custom codecs under the reuse 
path.

Report URL: https://github.com/apache/grails-core/actions/runs/28273949765

With regards,
GitHub Actions via GitBox

Reply via email to