Skip to content

use_sync_to_async Hook #84

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

Closed
wants to merge 4 commits into from

Conversation

Archmonger
Copy link
Contributor

@Archmonger Archmonger commented Jul 2, 2022

This hook is best way I can think of developing ORM query support, at least in a way that Django developers would understand.

Potentially closes the following

@Archmonger
Copy link
Contributor Author

Archmonger commented Jul 2, 2022

@rmorshea Let me know what you think about this implementation.

This hook can alternatively be named

  • use_sync_to_async_effect
  • use_safe_effect
  • use_orm_effect
  • use_effect_orm_safe
  • use_orm

@Archmonger Archmonger linked an issue Jul 2, 2022 that may be closed by this pull request
Comment on lines +27 to +28
if not categories:
return html.h2("Loading...")
Copy link
Contributor

@rmorshea rmorshea Jul 2, 2022

Choose a reason for hiding this comment

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

Part of the reason for the data, loading, error pattern is that the if not categories check does not actually indicate whether the query is loading - it could be that there are no categories to show, that loading categories failed, or that categories are indeed loading.

You also need a convenient way to re-execute queries that are related. For example, triggering an add_categories database operation should cause the get_categories effect to re-run. Not only that, but other components that loaded data from the Categories model might need to update as well.

While this PR does allow people to use the ORM within their components, I don't think it makes it convenient to handle all the edge cases. I've drafted an alternative (#86) that follows in the style of Apollo.

@Archmonger Archmonger mentioned this pull request Jul 4, 2022
3 tasks
@Archmonger Archmonger closed this Jul 6, 2022
@Archmonger Archmonger deleted the use-sync-to-async branch January 30, 2024 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Django ORM does not work well with IDOM
2 participants