-
Notifications
You must be signed in to change notification settings - Fork 224
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
[BUG] Inconsistent insertion behaviour depending on method used #1093
Comments
Having looked at the source code a bit, the more generalised issue seems to be that actions are not called for the If not, couldn't we use a decorator like the following to wrap these class methods to ensure the actions get run. Untested and type hints removed, so take with a grain of salt. Code:def wrap_classmethod_with_actions(event_type):
def decorator(f):
@wraps(f)
async def wrapper(cls, target, *args, skip_actions, **kwargs):
if skip_actions is None:
skip_actions = []
if isinstance(target, Document):
await ActionRegistry.run_actions(
target,
event_type=event_type,
action_direction=ActionDirections.BEFORE,
exclude=skip_actions,
)
elif isinstance(target, Iterable):
await asyncio.gather(
*[
ActionRegistry.run_actions(
document,
event_type=event_type,
action_direction=ActionDirections.BEFORE,
exclude=skip_actions,
)
for document in target
]
)
result = await f(
cls,
documents,
*args,
skip_actions=skip_actions,
**kwargs,
)
if isinstance(target, Document):
await ActionRegistry.run_actions(
target,
event_type=event_type,
action_direction=ActionDirections.AFTER,
exclude=skip_actions,
)
elif isinstance(target, Iterable):
await asyncio.gather(
*[
ActionRegistry.run_actions(
document,
event_type=event_type,
action_direction=ActionDirections.AFTER,
exclude=skip_actions,
)
for document in target
]
)
return result
return wrapper
return decorator |
Describe the bug
Transient fields and null fields get inserted into the database differently based on the insertion method used. See my example below. I'm new to Beanie, so apologies if I'm missing something obvious.
To Reproduce
Given the following example data model:
Running these three insertions:
Produces three inconsistent results:
model_dump
)."id": null
field is inserted in addition to the default mongo "_id" field - I think i'm supposed to specify this gets excluded inmodel_dump
).Expected behavior
The text was updated successfully, but these errors were encountered: