Application-defined datasources not available in the psuedo-constructor

Description

After creating a datasource in Application.cfc, I would expect to be able to access it right away. The datasource is not defined, however, in the psuedo-constructor. The datasource can be accessed in lifecycle methods like onRequestStart, but not in the psuedo-constructor.

The datasource is available in the psuedo-constructor if it was defined in the administrator.

There is a workaround — that is to update the datasources using the cfapplication tag, but this shouldn't be necessary as we are still in the Application.cfc.

ACF 2016 allows me to use the datasource immediately.

You can use this gist to recreate (only two files and a datasource connection are needed):
https://gist.github.com/elpete/ae7b5926a2f8ee97b9c6058626cd5182

Environment

MacOS 10.13.2
Java 1.8.0_144
Lucee 5.2.5.20

Activity

Show:

Eric Peterson 14 May 2019 at 18:13

I don’t remember the use case. I do know that ACF allows it.

Igal Sapir 14 May 2019 at 17:50

Can you explain the use case of using the datasource in the Application’s pseudo constructor?

Database requests are notoriously slow and executing a query every time in the pseudo constructor, as opposed to e.g. doing it once and storing the result in the Application scope is really not a good idea IMO.

Eric Peterson 14 May 2018 at 16:03

Yes, I've used the workaround. I think it is worth the work to make it work as expected, especially since ACF already supports it.

Michael Offner 7 May 2018 at 12:19

this needs a rethinking of how Application.cfc are loaded and a complete redo.
Not an easy talk, at least 12h of work.

Problem is that you are still in the prior application context when the pseudo constructor is loaded

there is a simple workaround for this, use the tag application:

Pothys - MitrahSoft 11 January 2018 at 16:17

I've added test case for this ticket & Confirmed the issue happened on lucee. If we create psuedo-constructor in Application.cfc means it will not available the datasource in cfdbinfo, But it is available in test.cfm page. It also available in application.cfc page while using within onRequestStart. ACF is working as expected.

Pull Request: https://github.com/lucee/Lucee/pull/369

Details

Assignee

Reporter

Priority

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Sprint

Affects versions

Created 11 January 2018 at 04:16
Updated 26 August 2019 at 18:38