Ticket #13790 (new Bug)
plone.supermodel parsing of xml happens too early
Reported by: | do3cc | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | 4.x |
Component: | Unknown | Version: | 4.3 |
Keywords: | Cc: |
Description
What I did: created a schema with a richtext field ttw. Added it as an xml file and used supermodels load function to add the schema. Created an adapter for the schema. Ran my plone.app.testing based tests.
What did I expect: That my tests run through
What actually happened: I've got an exception stating that my schema field for the Richtext field is invalid.
Additional information: This happens only when running the tests, not when starting the instance. I do not fully understand why.
I circumvented the problem by creating a marker interface in a different file. This way the schema is not loaded during zcml parsing.
I have no idea if this should be considered a plone.supermodel bug or something that needs to be documented somewhere. I am also surprised that the problem does not appear when starting zope in foreground. Apparently the zcml registration step is not a single step.
Change History
comment:2 Changed 2 years ago by davisagli
I'm not sure what the right way is to solve this in general in plone.supermodel, but you can work around it by being sure in your test setup to execute the zcml of the packages that register fields before importing the packages that load models into schemas.
It looks to me like the code for SchemaClass in plone.supermodel's model.py anticipates the following scenarios:
- Module with the schema is imported, then all ZCML is executed
- All ZCML is executed, then module with the schema is imported
but not this one:
- plone.supermodel's ZCML is executed, then module with the schema is imported, then ZCML to register a new field type is executed
One possible solution would be to register distributions that provide additional fields as z3c.autoinclude plugins of plone.supermodel, so that plone.supermodel has a way to indirectly include their ZCML from its own. This sucks slightly though, because z3c.autoinclude's scanning of packages is rather slow.
After explaining the issue to a friend, I see now that this is clearly a supermodel bug. The code tries to do things that require components during import time. That is wrong.