plone / plone.supermodel

Provides XML import and export for schema interfaces based on zope.schema fields
5 stars 8 forks source link

Avoid using the component architecture during parsing of xml schema #6

Open do3cc opened 10 years ago

do3cc commented 10 years ago

Right now, supermodel tries to access utilities during import time, when being used to define a schema of an interface. It may or may not be that at that time all utilities have been loaded, bring back one of the problems the zcml component architecture tried to solve, namely not depend on import orders. Currently, when I use supermodel schemas, I have to create a different marker interface, contained within a different module and then declare browser views for that marker interface. Else, my tests won't run, because supermodel cannot initialize my schema.

davisagli commented 10 years ago

Not using the component architecture would be a big backwards-incompatible change, but there's some work that should be done here.

Actually supermodel tries to defer loading of models, which is what uses utilities, until the end of configuration. This work is done by plone.supermodel.SchemaClass._SchemaClass_finalize, which is called from one of two places:

  1. from finalizeSchemas as a zcml:customAction with very high order, so it happens as one of the last actions
  2. when any schema class is initialized (with the idea that everything is imported before anything is configured, so during the import phase no adapters will be found and this will be a no-op, but after configuration they will be found and the model will be loaded immediately)

The problem happens if a schema gets imported in the middle of configuration (or test setup) at a point where the schema plugin adapters are registered but the various field handlers are not. We need to find a better way to defer loading until everything needed is in place.

MrTango commented 6 years ago

We discovert simmilar problems, when we are using subclassing of schema interfaces which uses model.load() to load xml files. If we try later to omit a field with autoform, it works but makes trouble in tests, complaining that the field we want to omit does not exists. In pure Python schema this does not hapen.