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

datetime converter breaks dexterity content types with datetime fields #4

Closed
frisi opened this issue Oct 7, 2016 · 10 comments · Fixed by #5
Closed

datetime converter breaks dexterity content types with datetime fields #4

frisi opened this issue Oct 7, 2016 · 10 comments · Fixed by #5

Comments

@frisi
Copy link
Contributor

frisi commented Oct 7, 2016

the converter introduced in this commit: e8a169b
breaks dexterity content with datetime fields: (ie from the plone.app.dexterity.behaviors.metadata.IPublication behaviour)

z3c.form checks if the widget value has been changed, and the converter installed here returns a timezone-aware datetime object and the datamanager returns the attribute stored for this behaviour without a timezone.

TypeError: can't compare offset-naive and offset-aware datetimes
> /home/frisi/.buildout/eggs/z3c.form-3.2.9-py2.7.egg/z3c/form/util.py(180)changedField()
    179 # Or it is an Object, in case we'll never know
    181 if (not dm.canAccess() or dm.query() != value):
ipdb> dm.query() # attribute 
datetime.datetime(2016, 10, 7, 17, 31, 25)
ipdb> value  # obtained by using the converter: interfaces.IDataConverter(widget).toFieldValue(raw)
datetime.datetime(2016, 10, 7, 17, 31, tzinfo=tzfile('/etc/localtime'))
@frisi
Copy link
Contributor Author

frisi commented Oct 7, 2016

@vladimir-iliev @vipod
using this converter for all datetimewidgets seems to break other use-cases

what problem did you solve by adding this converter?
is there another way to add timezone info to the notifications (ie. the getter-method or a customer indexer)?
another option might be to register it only for the widgets used in this package

@vipod
Copy link
Member

vipod commented Oct 8, 2016

@frisi I think @vladimir-iliev got an answer here.

But I'm not sure if he is still active here. So if we do not get reply in couple of days - feel free to make you decision.

@frisi
Copy link
Contributor Author

frisi commented Nov 9, 2016

adding timezone information makes sense. tests pass without the overrides.zcml (it was not even loaded for the test environment) but saving notices lead to an error (catalog only allows dates with timezone info)
i decided to remove the converter (that adds tzinfos to the data passed to the factory by the z3c.form) and add timezone information to the object properties if they get datetime objects w/o timezone info.

@vipod would be great if you can review the PR so i can make a release (if that's ok with you)

@vipod
Copy link
Member

vipod commented Nov 10, 2016

@frisi It looks like we changed datetime field value types we store in database. Don't we need also to add some kind of migration profile for this change? Would existing collective.notices installations still work after upgrade?

@frisi
Copy link
Contributor Author

frisi commented Nov 10, 2016

hey @vipod - thanks for you feedback!

actually there is no migration needed.
before this pull request, the custom converter registered for datetimewidgets added a timezone value to the date so it was stored with timezone.
now there is no converter and we make sure a timezone is added on class level.

old entries already have timezone info, new entries will have them automatically too.

after adding my changes there is no need to manually add the timezone for test-content (see changes in the test.py)

from my point of view existing installations will still work fine.

@vipod
Copy link
Member

vipod commented Nov 10, 2016

@frisi ok, thank you for explanation!

@vipod vipod closed this as completed in #5 Nov 10, 2016
@frisi
Copy link
Contributor Author

frisi commented Nov 10, 2016

you're welcome.
will you make a new release @vipod ?

@vipod
Copy link
Member

vipod commented Nov 10, 2016

Can you do this? I guess you got all the necessary permissions here and at pypy?

@frisi
Copy link
Contributor Author

frisi commented Nov 10, 2016

i guess so, too! will do!

@frisi
Copy link
Contributor Author

frisi commented Nov 10, 2016

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

Successfully merging a pull request may close this issue.

2 participants