-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
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
Use uppercase field names for VTODO in caldav #105386
Conversation
As per RFC5545 ical property names are always uppercase, and the `caldav` library we use automatically uppercases them while producing the ICAL stream. But this means that different casings (including the default values from the library) are treated as different `dict` keys and will be separately iterated on. This can create duplicate entries which are commonly forbidden by RFC5545. Use only uppercase in property names to alleviate this risk.
Note that the issue should be solved upstream by python-caldav/caldav#354 which maps all property names to lowercase to remove duplicates. It seems that the This fix, while not harmful even with later On the other hand, no |
When the arguments are coming in as parameters to a python function or method, then lowercase seems a lot more appropriate than uppercase to me - in other context, uppercase would be more appropriate. The primary task of the caldav library is to do the caldav communication, hence it should be mostrly agnostic to the icalendar content. In this case I've added a convenience-method for adding events or tasks to the calendar without the need of the caller to generate the icalendar content. There was a specific bug here adding a default status line when creating tasks, without considering that the input parameter would come in as lower case. When accessing the icalendar data, the recommended practice is to work on it through the icalendar library. In the icalendar library, the icalendar object is stored as a case-insensitive dict, meaning that the keys can be accessed either as upper case or lower case (or even CamelCase if one would prefer that). I hope to make a new release of the caldav library later this weekend or early next week, including this bugfix (and quite some other minor bugfixes). |
Yes, it makes sense to me that python function arguments should be lowercase. So it sounds like we consider this a bug in Would it be better to assert on the rfc5545 content in the test catch this type of issue? or keep that as an implementation detail of (Also this PR has test failures) |
Note that I also agree that arguments are prettier in lowercase. I was just pointing out that my workaround was going against the (IMHO correct) design choices of caldav API and thus should be only temporary if ever.
|
Thanks for clarifying. I think pulling in the upstream library bump sounds right given there is already a fix that was committed and it just needs to be released. |
I think there are some additional problems with how we're using The |
Is there a better way to use the Todo API so that we can call it the same way on create and update? I had a little trouble navigating the best way to handle this. |
I had a little go at that issue yesterday as well. The best I did come up with was always returning a Imho, that has the advantage, that the caldav library will be handling correct date/time formatting. It unfortunately broke the tests as well because of the different date handling. See #105435 |
I'm not sure how this is done today, but the recommended way to update fields in an event or task is like this:
The
The convenience-method The plan is to move If someone sees room for improvement in the API, then feel free to shout out. Having |
@tobixen is there an API to use that can share code when setting fields on initial create and update? That is I care less about if it's setting strings or objects just want to have a simple way to do it the same way in both scenarios. While there are lots of examples in the code, they seem to show very different ways for these two scenarios so I assume I'm missing something basic. Thanks! |
#105435 is a date fix showing the difference needed for create vs update. |
As for now, no - but we could make something. The obvious thing would be to create I think it would make sense to try to put as much as possible of the actual logic into the icalendar library rather than the caldav library. |
v1.3.8 is out. |
Awesome thank you @tobixen ! |
Drafting it as the following needs to be done first:
Please mark it as ready for review afterwards |
Testing locally within a python interpreter no longer raises the error and correctly adds the task which is then visible by HomeAssistant and all other caldav clients. I'd say this is fixed by the new caldav release. Do you want me to force-update the caldav library within my home assistant instance ? I should be able to do so using the privileged SSH addon. |
#105508 submitted instead of this PR which is unneeded I think. |
As per RFC5545 ical property names are always uppercase, and the
caldav
library we use automatically uppercases them while producing the ICAL stream.But this means that different casings (including the default values from the library) are treated as different
dict
keys and will be separately iterated on. This can create duplicate entries which are commonly forbidden by RFC5545.Use only uppercase in property names to alleviate this risk.
Breaking change
Proposed change
Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.To help with the load of incoming pull requests: