Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

composition interface is not added to the generated model by the models builder #11856

Closed
mariusAppstract opened this issue Jan 13, 2022 · 1 comment
Labels

Comments

@mariusAppstract
Copy link

mariusAppstract commented Jan 13, 2022

Which exact Umbraco version are you using? For example: 9.0.1 - don't just write v9

9.1.2

Bug summary

When I create a composition (eg. for error handling) an interface is not added to the generated model by the models builder.

Composition:
image
Generated code:
image

However, if I now create a document type and compose from this error handling composition, the interface is added to the generated code.
Document type:
image
Generated code:
image

This is a problem for code which is dependent on this interface - both other classes using the interface, but also when it comes to tests mocking with the interface - since a solution will not build if the composition is removed from the document type again. I've read this documentation (https://our.umbraco.com/Documentation/Reference/Templating/Modelsbuilder/Introduction), but I can't see whether or not this behavior is a feature or a bug - it seems weird to me though that the interface is not just added per default when a composition is created.

Specifics

Models builder version:
Umbraco.ModelsBuilder.Embedded v9.1.2+915f1cb34c3c63d3c88ebced61dd35d80255408c

Models builder mode:
image

Steps to reproduce

Steps to reproduce issue:

  1. Create a composition (with some properties), eg. 'TestComposition'
  2. Let models builder run
  3. Refer to the interface 'ITestComposition' in the code from another class or test

See expected/actual result here.

The following steps will fix the issue:
4. Create document type, eg. 'TestDocumentType'
5. Add 'TestComposition' to compositions in 'TestDocumentType'
6. Let models builder run

Issue will happen again if 'TestComposition' is removed from compositions in all document types.

Expected result / actual result

Expected result:
Creating a composition in back office and running models builder will generate code containing a partial interface for the composition as well as a partial class implementing this (and other) interface(s). This interface can then be used other places in code.

Actual result:
Interface is not created and can therefore not be used.

@nul800sebastiaan
Copy link
Member

Hi @mariusAppstract - I just tested these steps in v8.8 and indeed we get the same behavior here. I assume if the element is not used in a composition it could be used in nested content for example, at which point it's not being generated as an interface either.

I am sure this is inconvenient! However, this is how it's been working for as long as I can remember, so I would assume people have found workarounds or other ideas to deal with your scenario. I would recommend you ask around on the forum or do a search, I haven't looked myself, so not sure.

Of the top of my head I seem to remember there's ways to manipulate how models get generated but I don't have

Currently we have no plans to make changes to how the built-in ModelsBuilder works. The external ModelsBuilder package looks like it's looking for active maintainers though, maybe you can team up with them if you're craving some additional features?

modelsbuilder/ModelsBuilder.Original#258
image

As it stands, I will close this issue as expected behavior, even if it's not exactly what you were expecting, sorry I don't have better news for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants