minor: Use virtual_parent for custom fetchers.

The distinction here wasn't super meaningful
due to the way we order our "elif" statements,
but we want to reserver "normal_parent" for the
majority of use cases, where you simply tell
the Config what the "foreign_key" is.
This commit is contained in:
Steve Howell 2021-12-08 19:54:57 +00:00 committed by Tim Abbott
parent 50120a9387
commit 927b04368e
1 changed files with 8 additions and 1 deletions

View File

@ -457,6 +457,13 @@ class Config:
if self.custom_fetch:
# enforce a naming convention
assert self.custom_fetch.__name__.startswith("custom_fetch_")
if self.normal_parent is not None:
raise AssertionError(
"""
If you have a custom fetcher, then specify
your parent as a virtual_parent.
"""
)
if normal_parent is not None:
self.parent: Optional[Config] = normal_parent
@ -815,7 +822,7 @@ def get_realm_config() -> Config:
"_huddle_subscription",
"zerver_huddle",
],
normal_parent=user_profile_config,
virtual_parent=user_profile_config,
custom_fetch=custom_fetch_huddle_objects,
)