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

Strong types, not ignoring the VALUE parameter, better error handling #196

Closed
wants to merge 2 commits into from

Conversation

stlaz
Copy link
Collaborator

@stlaz stlaz commented Aug 12, 2016

Hello,
Long time no patch from me so I decided it might be good to finally improve error handling. I built the error handling improvements on top of #192 as I believe this patch may finally get it pushed.

@stlaz stlaz changed the title Error handling Improved error handling Aug 12, 2016
@stlaz
Copy link
Collaborator Author

stlaz commented Aug 16, 2016

I will leave running your Jenkins jobs on you if you don't mind.

@gforcada
Copy link
Member

@stlaz I just did (starting the jenkins jobs), you can find a guide on how to do that yourself next time here

@stlaz
Copy link
Collaborator Author

stlaz commented Aug 18, 2016

It would seem those tests failed if I see the right jobs.
http://jenkins.plone.org/job/pull-request-5.0/1349/
http://jenkins.plone.org/job/pull-request-5.1/536/
Do you know what causes the failure, @gforcada? The tests in python-icalendar, the only repository I really care about, pass. If those tests that do not pass are valid could you then add them to this repository instead?

Also, there should probably be better notification of test failure in the Pull Request report.

@stlaz
Copy link
Collaborator Author

stlaz commented Aug 30, 2016

@gforcada I believe the Internet revealed the string that should have made the test fail which is the one in test_portal_ical on Plone:tests.test_icalendar/. However, it does not seem to fail for me.
@geier or @thet, do you guys think you could look into it and possibly (N)ACK these changes for pushing? Thanks 👍

@staticmethod
def from_ical(ical, timezone=None):
@classmethod
def from_ical(cls, ical, unit_type=None, timezone=None):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep the old order of arguments, this breaks backwards compatibility otherwise.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, that wasn't clever at all, don't know why I did that. Should be fixed now.

@stlaz
Copy link
Collaborator Author

stlaz commented Sep 8, 2016

@gforcada I fixed the issue pointed out by @geier in a comment and decided to go ahead and run a Jenkins job according to the guide. Allowed the application to read whatever it wanted to read and I suddenly get "stlaz is missing the Overall/Read permission" on http://jenkins.plone.org/. This seems a bit funny to me because I have more read permissions as an anonymous user (when I'm not logged in).

@gforcada
Copy link
Member

gforcada commented Sep 8, 2016

@stlaz probably that's related to you not being in github.com/plone organization I think... I will run the jobs for you

@stlaz
Copy link
Collaborator Author

stlaz commented Sep 9, 2016

Still not sure why the IcalendarTestExportDX tests are failing, I was thinking they would be caused by the backward compatibility issues which I was hoping I fixed.
I shall look more into the decoded() method, I think possibly there might be bug in it not checking the VALUE parameter. However, if you look into the exception, you see that it's actually correct, '20130404' is indeed wrong datetime format.

@geier
Copy link
Collaborator

geier commented Sep 10, 2016

I've created https://github.com/geier/icalendar/tree/fix_failures to help pinpoint those errors.

@@ -402,6 +429,10 @@ def from_ical(ical, timezone=None):
tzinfo = _timezone_cache.get(timezone, None)

try:
if ical[8] != 'T':
Copy link
Collaborator

@geier geier Sep 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check for length here

ignore that

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will swap this check with the length check to make it a bit cleaner.

@stlaz
Copy link
Collaborator Author

stlaz commented Sep 13, 2016

Thanks @geier, that helped! I was able to find the issues with the decoded() method. Still not able to reproduce the IcalendarTestExportDX issue.
Btw: There's an error in those tests you uploaded. The error is on lines 63, 64 of plone.app.event.icaltest.ics and on lines 61, 62 of src/icalendar/tests/plone.app.event.icaltest_2.ics. The 'DTSTART' and 'DTEND' property type defaults to 'DATE-TIME' in RFC 5545 (not sure if this is a change to the previous version) therefore 'VALUE=DATE' has to be defined.

@thet
Copy link
Member

thet commented Oct 26, 2016

@gforcada @stlaz I think people contributing to icalendar shouldn't deal with Plone's CI suite.
icalendar is used quite a lot out of the Plone context. Passing travis tests is all what's required.

@gforcada what is needed to remove the Plone CI integration?

@stlaz
Copy link
Collaborator Author

stlaz commented Oct 26, 2016

@thet: This time it helped to reveal a bug so I was happy we had it there :) But you, Plone, can always run those tests yourself and open an Issue if something is broken by my patches, mark me as an Assignee and I shall have a look at it. That seems a bit more reasonable than having CI tests that the community can't run anyway.

@geier
Copy link
Collaborator

geier commented Oct 26, 2016

@stlaz sorry, somehow I didn't see your replies, I know these the test data isn't RFC5545 compliant, but it's what the plone people use, so I'm sure they wouldn't appreciate it if we broke this in a non-major release.

And yes, this is somewhat inconsistent with the behavior of icalendar in other places, like only accepting timeshifts for VTIMEZONE components <= 24h. I'm actually in favor of some kind of strict or lenient mode for icalendar.

@stlaz
Copy link
Collaborator Author

stlaz commented Oct 27, 2016

@geier If I recall correctly, originally this patch enabled lazier approach to parsing iCalendar strings, leaving strange values at the given property as strings, while also keeping the property parameters. This should allow the user of the parser to evaluate the value according to their needs instead of parsing it in a wrong way and possibly dropping some of the parameters on the way.
That being said, wouldn't it be time to get the major version features prepared so that new major version could be released? :)

@geier
Copy link
Collaborator

geier commented Oct 27, 2016

That being said, wouldn't it be time to get the major version features prepared so that new major version could be released? :)

I fully agree, but at the moment I do not have a lot of time for this.

Previously, if error occured during the creation of inner
type instance from iCalendar string, the error with the
name of the bogus property would be stored in the
appropriate component's errors attribute along with the error
string  but the property's value would be removed from the
parsed representation. This patch keeps the value even with its
parameters at that certain property, the value's type is changed
to vText.

Should allow implementation of
collective#158

Improves
collective#174
@stlaz stlaz changed the base branch from master to devel-4.0 July 20, 2017 07:07
@stlaz stlaz changed the title Improved error handling Strong types, not ignoring the VALUE parameter, better error handling Jul 20, 2017
for dt in dt_list:
dt = vDDDTypes(dt)
# raise ValueError if type of the input values differs
if not isinstance(dt, ltype):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this test fail if the first element in the list is a date and the later ones are datetime? I believe we will need to actually do a if type(dt) != type(ltype) here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, you're right, it would seem that we need to be even more strict here. Thanks for pointing that out with the date/datetime example, I did not realize.

@geier
Copy link
Collaborator

geier commented Jul 24, 2017

I have used khal's testsuite as an additional test for this PR and while I have found an issue, minimal example as follows:

import icalendar
import datetime as dt
event = icalendar.Event()                                                                                                                                                        
event.add('DTSTART', dt.date.today())                                                                                                                                            
event.to_ical()

leads to an AttributeError:

  File "<stdin>", line 1, in <module>
  File "/usr/home/cg/workspace/icalendar/src/icalendar/cal.py", line 450, in to_ical
    content_lines = self.content_lines(sorted=sorted)
  File "/usr/home/cg/workspace/icalendar/src/icalendar/cal.py", line 439, in content_lines
    cl = self.content_line(name, value, sorted=sorted)
  File "/usr/home/cg/workspace/icalendar/src/icalendar/cal.py", line 432, in content_line
    return Contentline.from_parts(name, params, value, sorted=sorted)
  File "/usr/home/cg/workspace/icalendar/src/icalendar/parser.py", line 304, in from_parts
    values = values.to_ical()
  File "/usr/home/cg/workspace/icalendar/src/icalendar/prop.py", line 404, in to_ical
    tzid = tzid_from_dt(dt)
  File "/usr/home/cg/workspace/icalendar/src/icalendar/parser.py", line 52, in tzid_from_dt
    if hasattr(dt.tzinfo, 'zone'):
AttributeError: 'datetime.date' object has no attribute 'tzinfo'

@geier
Copy link
Collaborator

geier commented Jul 24, 2017

Documentation issue: accessing a DURATION's timedelta changed from event['DURATION'].dt to event['DURATION'].td.

@stlaz
Copy link
Collaborator Author

stlaz commented Jul 26, 2017

The documentation issue did not appear in this PR for the first time though, did it?

@geier
Copy link
Collaborator

geier commented Jul 26, 2017

I believe it does, the following snippet works on master but not with this PR:

import icalendar
import datetime as dt
event = icalendar.Event()
event.add('DURATION', dt.timedelta(hours=2))
print(event['DURATION'].dt)

@stlaz
Copy link
Collaborator Author

stlaz commented Aug 15, 2017

Hello,
Sorry I did not update the PR recently, I was on a vacation away from my laptop. I have some work to do this week but i hope I'll get to this by the end of it.

I believe the dt -> td doc issue is caused by the duration property actually correctly resolving to the vDuration type so it's indeed just a doc issue.

I need to look more closely on the first issue though. It's apparent that datetime.date object would not have tzinfo attribute, I'll just need to see how much we should care :)

@stlaz
Copy link
Collaborator Author

stlaz commented Nov 3, 2017

I am sorry I did not get enough time for this for the past few months, a lot happened. I should hope to get to this real soon, hopefully.

A note to the failure with the simple example event.add('DTSTART', dt.date.today()). This will create an invalid event since DTSTART expects DATE-TIME value by default. This should be handled more properly during to_ical I guess.

@thet
Copy link
Member

thet commented Oct 13, 2021

Revisiting this after more than 5 years!
I resolved the last mentioned issues from the comments in: #331
Thanks @stlaz for your work and @geier for the in-depth review!

I think we can get #331 merged before the RFC5545 standard or computers at all eventually becomes obsolete.

@thet thet closed this Oct 13, 2021
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 this pull request may close these issues.

4 participants