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

collectionviews: Ignore session state if it uses the wrong format #909

Merged
merged 3 commits into from
Feb 9, 2024

Conversation

dylanmccall
Copy link
Collaborator

@dylanmccall dylanmccall commented Feb 7, 2024

It is possible for COLLECTIONS_STATE to be populated with data from a previous version of kolibri-explore-plugin, which results in unhandled errors in new code which expects it to be in a different format.

https://phabricator.endlessm.com/T35159

@dylanmccall dylanmccall requested a review from starnight February 7, 2024 21:05
@dylanmccall dylanmccall force-pushed the T35159-validate-saved-state branch 2 times, most recently from a94375b to 389270b Compare February 7, 2024 23:36
@dylanmccall dylanmccall changed the title collectionviews: Ignore session state if it uses the previous format collectionviews: Ignore session state if it uses the wrong format Feb 7, 2024
kolibri_explore_plugin/collectionviews.py Outdated Show resolved Hide resolved
kolibri_explore_plugin/collectionviews.py Outdated Show resolved Hide resolved
It is possible for COLLECTIONS_STATE to be populated with data from a
previous version of kolibri-explore-plugin, which results in unhandled
errors in new code which expects it to be in a different format.

https://phabricator.endlessm.com/T35159
This view was accessing "name" and "sequence" items in the collection
manager state object. These have been renamed to "collection_name" and
"collection_sequence".

https://phabricator.endlessm.com/T35159
@dylanmccall dylanmccall force-pushed the T35159-validate-saved-state branch from 389270b to 8542bd1 Compare February 9, 2024 00:25
@dylanmccall dylanmccall requested a review from wjt February 9, 2024 01:32
Copy link
Member

@wjt wjt left a comment

Choose a reason for hiding this comment

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

I have a query about the new locking. If I am misunderstanding and the lock does need to be held while calling the wrapped_function, then consider this an approval.

with ENSURE_INITIATED_RLOCK:
if _collection_download_manager is None:
_read_content_manifests()
return api_function(*args, **kwargs)
Copy link
Member

Choose a reason for hiding this comment

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

Is it intentional that the wrapped function is called with the lock held?

IIUC, the lock is meant to ensure that _read_content_manifests() is called only once; so I would expect that the lock could be released before calling the wrapped api_function. But I'm probably wrong!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ooh yes, that isn't intentional. Thanks for noticing :)

It is possible for concurrent requests to be served by different threads
in the same Python process, resulting in unexpected behaviour if the
wrapper function from ensure_initiated is not finished executing for the
first time. To solve this, wrap the critical code in a lock.

https://phabricator.endlessm.com/T35159
@dylanmccall dylanmccall force-pushed the T35159-validate-saved-state branch from d4db24e to 4743786 Compare February 9, 2024 22:22
@dylanmccall dylanmccall merged commit 419210a into master Feb 9, 2024
3 checks passed
@dylanmccall dylanmccall deleted the T35159-validate-saved-state branch February 9, 2024 22:57
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.

2 participants