-
Notifications
You must be signed in to change notification settings - Fork 137
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
fix: return default with get #748
base: master
Are you sure you want to change the base?
Conversation
The dict structure and behaviour of SurveyElement has, and continues to be, a major source of performance and correctness problems. To address this, recently I have been working towards making SurveyElement not a dict, and the change to Mapping (which does not require a If you want to use continue to use SurveyElement externally, I would suggest updating your code to switch from assuming dict access to using attribute access, either:
As a side note it would be helpful in future if you please add some context e.g. what is your calling code and use case that requires this change, ideally in the form of an ODK forum discussion. I have searched GitHub a few times for libraries using pyxform as a library, but not found much. There's some references in ona / kpi repos but it seemed also like key parts of pyxform had been copied / vendorised anyway. I consider the |
According to https://docs.python.org/3/library/collections.abc.html#collections-abstract-base-classes
Would you prefer to continue this discussion there? I thought this would be a bug fix so I just made a straight up PR but since there's more to it I can go to the forum. |
Hi and welcome, @rgraber! @lindsay-stevens has been the primary maintainer of I just realized I was supposed to add a note about breaking changes in the release notes for v3.0.0 but did not. I've added it now: https://github.com/XLSForm/pyxform/releases/tag/v3.0.0 Since this issue is developer-facing, let's keep the conversation going here and we can pull in others or increase visibility if needed. 😊 I imagine @ukanga has run into this too and will be interested in following along. I know these breaking changes may appear frivolous but we promise they have user-facing value! As @lindsay-stevens mentioned, form parsing is now much, much faster across the board with some forms that took minutes to go from XLSForm to XForm now taking seconds. I think neither of us considered that At a high level, in what context do you get Contract violation aside, would it be onerous for you to switch to one of the usages @lindsay-stevens has suggested above? I'm asking because as he hinted at, we're contemplating a deeper move away from dict-like access and it'd be helpful to get a sense of impact for you. That will also be info we consider for how to handle the issue in the immediate term -- fix Are you affected by other breaking changes from 3.0.0 or is this the only one? @lindsay-stevens and I will work together to get this resolved in the next week. Thanks! |
Hello @lognaturel :) We did manage to get around the problem by using |
Here is the PR we used to fix all the issues that came with the upgrade: kobotoolbox/kpi#5442 . It unfortunately has a lot of formatting changes too because of how our formatting process works, but generally the important part is the implementation of |
Why is this the best possible solution? Were any other approaches considered?
Mapping classes have a default
get
method that accepts a default and returns it if the key requested is not found. Though SurveyElement has been updated to rely more on attributes than keys, it breaks the Mapping contract to haveget
not work as expected with a default (it will currently return an AttributeError if the attribute is not found).The alternative would be to update getitem to turn an AttributeError into a KeyError so it could be properly caught by the default
get
method. However,element[key]
may still be called in several places and I do not want to risk undermining any assumptions about how it currently works.What are the regression risks?
There shouldn't be any, this is a return to expected behavior.
Does this change require updates to documentation? If so, please file an issue here and include the link below.
Before submitting this PR, please make sure you have:
tests
python -m unittest
and verified all tests passruff format pyxform tests
andruff check pyxform tests
to lint code