Strange event mutation behaviour in loop
mquantin opened this issue · comments
Matthieu Quantin commented
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"
Niko Fink commented
Please try with the current alpha, which drops arrow and fixes a lot of serializer weirdness