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

TypeError: can't compare offset-naive and offset-aware datetimes #213

Open
zopyx opened this issue Feb 16, 2016 · 1 comment
Open

TypeError: can't compare offset-naive and offset-aware datetimes #213

zopyx opened this issue Feb 16, 2016 · 1 comment

Comments

@zopyx
Copy link
Member

zopyx commented Feb 16, 2016

According to

https://ploneappevent.readthedocs.org/en/latest/development.html#getting-and-setting-properties

the following error should not happen.
(Plone 5.0.2, plone.app.event 2.0.3)

bin/instance run scripts/new-site.py omicron
Traceback (most recent call last):
  File "/home/ajung/sandboxes/omicron_buildout/parts/instance/bin/interpreter", line 280, in <module>
    exec(_val)
  File "<string>", line 1, in <module>
  File "scripts/new-site.py", line 100, in <module>
    obj.reindexObject()
  File "/home/ajung/.buildout/eggs/Products.CMFCore-2.2.10-py2.7.egg/Products/CMFCore/CMFCatalogAware.py", line 88, in reindexObject
    catalog.reindexObject(self, idxs=idxs)
  File "/home/ajung/.buildout/eggs/Products.CMFCore-2.2.10-py2.7.egg/Products/CMFCore/CatalogTool.py", line 301, in reindexObject
    self.catalog_object(object, uid, idxs, update_metadata)
  File "/home/ajung/.buildout/eggs/Products.CMFPlone-5.0-py2.7.egg/Products/CMFPlone/CatalogTool.py", line 345, in catalog_object
    update_metadata, pghandler=pghandler)
  File "/home/ajung/.buildout/eggs/Products.ZCatalog-3.0.2-py2.7.egg/Products/ZCatalog/ZCatalog.py", line 476, in catalog_object
    update_metadata=update_metadata)
  File "/home/ajung/.buildout/eggs/Products.ZCatalog-3.0.2-py2.7.egg/Products/ZCatalog/Catalog.py", line 347, in catalogObject
    self.updateMetadata(object, uid, index)
  File "/home/ajung/.buildout/eggs/Products.ZCatalog-3.0.2-py2.7.egg/Products/ZCatalog/Catalog.py", line 311, in updateMetadata
    if data.get(index, 0) != newDataRecord:
TypeError: can't compare offset-naive and offset-aware datetimes
make: *** [new-site] Error 1
for i in range(10):

    id = 'event-{}'.format(i+1)
    start = datetime.now().replace(hour=9, minute=0, second=0)
    end = start + timedelta(days=2)
    end = end.replace(hour=17)

    path = '{}/de/kurse-termine/{}'.format(site_id, id) 
    obj = plone.api.content.create(type='Event', container=root['kurse-termine'], id=id)
    obj.setTitle(gen_sentence())
    obj.setDescription(gen_paragraphs(1))
    text = gen_sentences()
    obj.text = RichTextValue(text, 'text/html', 'text/html')
    obj.contact_name = u'Heinz Becker'
    obj.contact_email = u'[email protected]'
    obj.contact_phone = '+49 1234 1212121'
    obj.event_url = u'https://www.plone.org'
    plone.api.content.transition(obj, 'publish')
    event = IEventBasic(obj)
    event.start = start
    event.end = end
    event.timezone = 'CT'
    obj.reindexObject()
@zopyx
Copy link
Member Author

zopyx commented Feb 16, 2016

Solved the problem by


    start = (datetime.now() + timedelta(days=random.randint(2, 365))).replace(hour=9, minute=0, second=0)
    start = start.replace(tzinfo=pytz.UTC)
    end = start + timedelta(days=2)
    end = end.replace(hour=17)

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

No branches or pull requests

1 participant