-
Notifications
You must be signed in to change notification settings - Fork 211
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
Allow change class_id and use name settings in UnionDoc #466
Allow change class_id and use name settings in UnionDoc #466
Conversation
@@ -233,8 +233,9 @@ async def init_document_collection(self, cls): | |||
# register in the Union Doc | |||
|
|||
if document_settings.union_doc is not None: | |||
name = cls.get_settings().name or cls.__name__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if cls.get_settings().name
always returns original class name instead of None when name is not set, we wouldn't need this line.
@@ -24,7 +24,7 @@ def parse_obj( | |||
raise UnionHasNoRegisteredDocs | |||
|
|||
if isinstance(data, dict): | |||
class_name = data["_class_id"] | |||
class_name = data[model.get_settings().class_id] | |||
else: | |||
class_name = data._class_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it ever reach line 29 for UnionDoc? it didn't for my (small) dataset
@@ -24,7 +24,7 @@ def parse_obj( | |||
raise UnionHasNoRegisteredDocs | |||
|
|||
if isinstance(data, dict): | |||
class_name = data["_class_id"] | |||
class_name = data[model.get_settings().class_id] | |||
else: | |||
class_name = data._class_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if class_name not in model._document_models: # type: ignore
raise DocWasNotRegisteredInUnionClass
This line seems too strict - especially in event source DB. One MSA can add a new event and boom we now have an error. if there is schema that beanie doesn't yet know perhaps gracefully skip?
Hi @wonjoonSeol-WS , |
This PR is stale because it has been open 45 days with no activity. |
…name-for-uniondoc
Merged. Thank you very mush for the PR. |
Beanie is all sound and good until there is a need to connect to existing DB where beanie is/was not used.
For instance, one might have SNS -> SQS -> lambda (that uses any other client other than beanie) -> DocDB / Mongo.
In case like this, the existing data would not have beanie's internal data field such as '_class_id".
This makes switching to Beanie difficult as it requires full DB migration, especially if DB is used for event-sourcing.
This PR allows (1) custom internal data field name to be set and (2) custom name to be set in Union doc children classes.
Usage:
Example:
Schema
Test
FYI, #206 this PR was not reviewed for a year so I closed it..