4teamwork / ftw.builder

Builder pattern for creating Plone objects in tests
3 stars 0 forks source link

DX-Builder: Initialize attributes only with set_field_values. #45

Closed deiferni closed 9 years ago

deiferni commented 9 years ago

This PR fixes an issue with field initialization from a builders arguments as set by having or similar methods.

When creating dexterity content the builder passes all arguments to createContent in addition to setting them with set_field_values. This is problematic for annotation-storage fields since the field is set as attribute on the created object as well. This will lead do unpickleable content in some cases, e.g. when setting relations.

This PR fixes that problem by no longer passing all arguments to createContent but only 'id' and 'title'. Unfortunately this causes further problems with plone because an IObjectCreatedEvent is fired by createContent, after which plone or our packages may expect the content object to have its fields initialized. This issue is adressed by implementing our own _create_content method which does not fire an IObjectCreatedEvent, firing the event is deferred until after all fields and defaults have been set by the builder.

(This issue seems to have been adressed in 'createContent' of newer plone.dexterity versions, but is not yet fixed as of version 2.1.3)

jone commented 9 years ago

Very nice! Thanks! :+1: :sparkles: