matrei opened a new issue, #16454:
URL: https://github.com/apache/grails-core/issues/16454

   The Spring configuration metadata in `grails-core`
   (`META-INF/additional-spring-configuration-metadata.json`, also merged into 
`spring-configuration-metadata.json`)
   documents defaults for several `dataSource.*` properties that differ from 
what an application actually gets. The
   runtime defaults come from 
`org.grails.datastore.gorm.jdbc.connections.DataSourceSettings`
   (`grails-datamapping-core`).
   
   The new `configReport` command prints the metadata defaults in its "Default" 
column, and IDEs show them in
   completion, so users are told a value applies when it doesn't.
   
   Verified with a minimal Grails 8.0.0-RC2 application 
(`grails-data-hibernate7`, H2, HikariCP, one domain class `Book`,
   **no `dataSource` configuration**), in the `development`, `production` and 
`test` environments. The results were the
   same in all three:
   
   | Property | Documented default (metadata) | Actually used |
   |---|---|---|
   | `dataSource.url` | `jdbc:h2:mem:devDb` | 
`jdbc:h2:mem:grailsDB;LOCK_TIMEOUT=10000` |
   | `dataSource.dbCreate` | `create-drop (dev), none (prod)` | `none`: 
`hibernate.hbm2ddl.auto` is `none` and the `BOOK` table is not created, also in 
`development` |
   | `dataSource.username` | `sa` | none: `HikariDataSource.username` is 
`null`; H2 connects with user `''` |
   | `dataSource.password` | `""` | none (`null`) |
   | `dataSource.driverClassName` | `org.h2.Driver` | not set; HikariCP derives 
`org.h2.Driver` from the URL |
   
   These match the field initialisers of `DataSourceSettings` (8.0.0-RC2):
   
   ```groovy
   String url = 'jdbc:h2:mem:grailsDB;LOCK_TIMEOUT=10000'
   String driverClassName
   String username
   String password
   ...
   String dbCreate = 'none'
   ```
   
   `toHibernateProperties()` only passes `username`/`password` on when they are 
set (`if (username)` /
   `if (password)`). The only place `create-drop` is used as a default seems to 
be the convenience constructor
   `HibernateDatastore(Class...)`, which applications don't use.
   
   The documented values look like the ones a generated application's 
`application.yml` contains, rather than the
   framework's own defaults.
   
   ### Expected Behavior
   
   The metadata (and therefore `configReport` and IDE completion) documents the 
defaults that are actually applied.
   
   ### Actual Behaviour
   
   Without `dataSource` configuration, an application uses 
`jdbc:h2:mem:grailsDB;LOCK_TIMEOUT=10000`, creates no schema
   (`dbCreate` `none`, also in development) and connects without credentials, 
while the metadata and `configReport`
   state `jdbc:h2:mem:devDb`, `create-drop` in development, and `sa` with an 
empty password.
   
   ### Steps To Reproduce
   
   1. Create a Grails 8.0.0-RC2 application with `grails-data-hibernate7`, H2 
and HikariCP, a domain class `Book`, and
      no `dataSource` block in `application.yml`.
   2. Run `./gradlew configReport`: the DataSource section shows 
`jdbc:h2:mem:devDb`, `create-drop`, `sa` and an empty
      password as defaults.
   3. Run the application (`./gradlew bootRun -Dgrails.env=development`, and 
likewise `production` and `test`) and, in
      `BootStrap`, inspect GORM's default datasource
      
(`hibernateDatastore.connectionSources.defaultConnectionSource.dataSource`), a 
connection's
      `metaData.URL`/`metaData.userName`, 
`sessionFactory.properties['hibernate.hbm2ddl.auto']`, and whether table `BOOK`
      exists.
   4. In every environment: URL `jdbc:h2:mem:grailsDB;LOCK_TIMEOUT=10000`, pool 
username `null`, connection user `''`,
      `hibernate.hbm2ddl.auto` `none`, and no `BOOK` table.
   
   ### Suggested Fix
   
   Make the metadata describe the real defaults rather than introduce new ones. 
Defaulting credentials to `sa`/`""`
   would be wrong for any database other than H2.
   
   - `dataSource.url`: `jdbc:h2:mem:grailsDB;LOCK_TIMEOUT=10000`.
   - `dataSource.dbCreate`: `none`, unless a per-environment default is meant 
to exist, in which case it needs
     implementing.
   - `dataSource.username` / `dataSource.password`: no `defaultValue`; the 
description could mention that H2 apps
     usually set `sa` / `""`.
   - `dataSource.driverClassName`: no `defaultValue`, or a description saying 
it is derived from the URL.
   
   A test that compares the documented `dataSource.*` defaults with 
`DataSourceSettings`' field initialisers would keep
   them from drifting apart again.
   
   ### Environment Information
   
   - Grails 8.0.0-RC2 (`grails-core`, `grails-datamapping-core`, 
`grails-data-hibernate7` 8.0.0-RC2)
   - H2 2.4.240, HikariCP 7.0.2
   - JDK 21
   
   ### Example Application
   
   _No response_
   
   ### Version
   
   8.0.0-RC2
   


-- 
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]

Reply via email to