Subsystem error when using load listener to add an alias #443

Closed
mjclemente opened this Issue Jul 26, 2016 · 8 comments

Comments

Projects
None yet
2 participants
@mjclemente

This is a bit of an edge case, and there is a workaround. It just took me a while to track down today.

I've set up a repo with a test case to demonstrate this: https://github.com/mjclemente/fw1alias

Steps to reproduce:

  • Set the application flag reloadApplicationOnEveryRequest=true
  • Use a loadlistener to set an alias for a service beanFactory.addAlias("alsoKnownAs", "existingService")
  • If you try to access a subsystem page (?action=module:main.default), it errors with "Element existingService is undefined in a CFML structure referenced as part of an expression." Examining beanfactory.getbeaninfo() shows that only the subsystem controller objects have been added at this point.
  • You are able to access pages within the default subsystem without issue.
  • You can work around it by declaring the bean before setting the alias beanFactory.declareBean( "departmentService", "model.services.department" ).
@seancorfield

This comment has been minimized.

Show comment
Hide comment
@seancorfield

seancorfield Jul 26, 2016

Member

This does not fail for me with FW/1 4.0.0 Beta 2. Which version of FW/1 are you using?

Member

seancorfield commented Jul 26, 2016

This does not fail for me with FW/1 4.0.0 Beta 2. Which version of FW/1 are you using?

@mjclemente

This comment has been minimized.

Show comment
Hide comment
@mjclemente

mjclemente Jul 26, 2016

The initial test repo that I initially created was 3.5. I just added a develop branch to it with 4.0.2, but it's responding the same way: error when set to reload on every request, but fine if that is disabled.

The test case repo is pretty bare bones, but it could be that I'm missing something and there's something else in the setup that's causing the error.

I should mention, I have tested it on ACF 11 and Lucee 4.5, with the same results.

mjclemente commented Jul 26, 2016

The initial test repo that I initially created was 3.5. I just added a develop branch to it with 4.0.2, but it's responding the same way: error when set to reload on every request, but fine if that is disabled.

The test case repo is pretty bare bones, but it could be that I'm missing something and there's something else in the setup that's causing the error.

I should mention, I have tested it on ACF 11 and Lucee 4.5, with the same results.

@seancorfield

This comment has been minimized.

Show comment
Hide comment
@seancorfield

seancorfield Jul 26, 2016

Member

I cloned your repo into the tests folder inside my local FW/1 dev setup and hit http://fw1.local:8080/tests/fw1alias/index.cfm?action=module:main.default repeatedly. No errors. Using the dev version of FW/1 (not the one in your repo).

Member

seancorfield commented Jul 26, 2016

I cloned your repo into the tests folder inside my local FW/1 dev setup and hit http://fw1.local:8080/tests/fw1alias/index.cfm?action=module:main.default repeatedly. No errors. Using the dev version of FW/1 (not the one in your repo).

@seancorfield

This comment has been minimized.

Show comment
Hide comment
@seancorfield

seancorfield Jul 26, 2016

Member

Cloned your repo elsewhere and checked out develop, then used box start to run a server and now I see your exception. Interesting.

Member

seancorfield commented Jul 26, 2016

Cloned your repo elsewhere and checked out develop, then used box start to run a server and now I see your exception. Interesting.

@mjclemente

This comment has been minimized.

Show comment
Hide comment
@mjclemente

mjclemente Jul 26, 2016

Ahh. Ok. At least I'm not entirely crazy.

mjclemente commented Jul 26, 2016

Ahh. Ok. At least I'm not entirely crazy.

@seancorfield

This comment has been minimized.

Show comment
Hide comment
@seancorfield

seancorfield Jul 26, 2016

Member

I was actually puzzled I couldn't repro because I expected the error: your load listener triggers for all your bean factories, both the main (parent) and the subsystem (child) ones. addAlias() assumes you are adding an alias for a bean in the same factory so when your load listener is run for the subsystem bean factory, it tries to create an alias to a bean that is in the parent bean factory -- which fails.

This has come up on Slack and/or on the list but I don't think the documentation mentions it and I'm not quite sure how best to solve the problem for the general case. The "obvious" case is to only run the load listener for bean factories with no parent but that excludes custom configurations where a dev is setting up parent/child bean factories themselves and actually wants a load listener -- potentially a different load listener -- run on each.

Member

seancorfield commented Jul 26, 2016

I was actually puzzled I couldn't repro because I expected the error: your load listener triggers for all your bean factories, both the main (parent) and the subsystem (child) ones. addAlias() assumes you are adding an alias for a bean in the same factory so when your load listener is run for the subsystem bean factory, it tries to create an alias to a bean that is in the parent bean factory -- which fails.

This has come up on Slack and/or on the list but I don't think the documentation mentions it and I'm not quite sure how best to solve the problem for the general case. The "obvious" case is to only run the load listener for bean factories with no parent but that excludes custom configurations where a dev is setting up parent/child bean factories themselves and actually wants a load listener -- potentially a different load listener -- run on each.

seancorfield added a commit that referenced this issue Jul 26, 2016

Adjust subsystem factory setting inheritance #443
Ensure that `loadListener` setting is not inherited by subsystem bean
factories but a custom subsystem bean factory configuration can still
specify a `loadListener` if that's what the developer wants (be
careful!).

seancorfield added a commit that referenced this issue Jul 26, 2016

@seancorfield

This comment has been minimized.

Show comment
Hide comment
@seancorfield

seancorfield Jul 26, 2016

Member

OK, download the develop version of FW/1 (it'll be 4.0.0-rc1 now for one.cfc -- the other files have not yet changed) and it should fix your problem.

Member

seancorfield commented Jul 26, 2016

OK, download the develop version of FW/1 (it'll be 4.0.0-rc1 now for one.cfc -- the other files have not yet changed) and it should fix your problem.

@seancorfield seancorfield added the bug label Jul 26, 2016

@seancorfield seancorfield added this to the 4.0 milestone Jul 26, 2016

@seancorfield seancorfield self-assigned this Jul 26, 2016

@mjclemente

This comment has been minimized.

Show comment
Hide comment
@mjclemente

mjclemente Jul 26, 2016

Thanks @seancorfield! That resolved it for me.

Thank you for the explanation as well. I understand the issue/framework a bit deeper now as well.

Thanks @seancorfield! That resolved it for me.

Thank you for the explanation as well. I understand the issue/framework a bit deeper now as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment