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

Strange event mutation behaviour in loop #404

Open
mquantin opened this issue Oct 20, 2023 · 1 comment
Open

Strange event mutation behaviour in loop #404

mquantin opened this issue Oct 20, 2023 · 1 comment

Comments

@mquantin
Copy link

mquantin commented Oct 20, 2023

I wrote event.start instead of event.begin (my error).
I hardly debugged it.
Cause I observed stranges behaviour (mutation).

above loop V1 an loopv2 should return the same result, isn't it?
There is maybe something I did'nt understand...

Minimal working example:

Common part

oldestEvent  = arrow.get("18/9/2023 4:00", "D/M/YYYY H:m")
with open(calendarPath, 'r') as icsFile:
    ics_text = icsFile.read()

skiped = 0
kept = 0
c = Calendar(ics_text) 

Loop v1 (OK):

for e in c.events:
    newE = Event
    if e.begin < oldestEvent:
        skiped += 1
        continue
    else:
        kept += 1
    start = e.begin.clone() #with intermediate variable
    newE.start = start
print(skiped)

Loop v2 (Strange): Change in line 8 of that loop

for e in c.events:
    newE = Event
    if e.begin < oldestEvent:
        skiped += 1
        continue
    else:
        kept += 1
#   start = e.begin.clone() #without intermediate variable
    newE.start = e.begin.clone()
print(skiped)

Also when I was trying to export I got unclear error (maybe this could be improved)

Traceback (most recent call last):
  File "/home/matthieu/Downloads/calendarEdit.py", line 44, in <module>
    f.writelines(out.serialize())
  File "/home/matthieu/.local/lib/python3.10/site-packages/ics/component.py", line 72, in serialize
    output(self, container)
  File "/home/matthieu/.local/lib/python3.10/site-packages/ics/serializers/icalendar_serializer.py", line 27, in serialize_event
    container.append(event.serialize())
TypeError: Component.serialize() missing 1 required positional argument: 'self'

All of this due to the creation of an unexpected object variable "event.start"

@N-Coder
Copy link
Member

N-Coder commented Nov 7, 2023

Please try with the current alpha, which drops arrow and fixes a lot of serializer weirdness

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

2 participants