Comments (3)
The proposal will solve this issue on a small level, but when the payload size is big and there are multiple consumers who are consuming the dispatched event at the same time this will become a big issue it will block all the memory. Especially for long-running tasks or coroutines.
A quick fix that comes into my mind is writing a wrapper inside dispatch to make the payload a frozen dict.
multiple handlers could accept it, frozen dict won't change. if anyone wants to change any property of that dict they could create a separate copy of that dict or get items from that dict.
from fastapi-events.
@danielhasan1 you're right. I haven't tried to address this issue because the payload
can technically be of any type, not just dict
. Either approach risks breaking the user's code if the payload contains values (custom objects, etc) that cannot be cloned or frozen.
I'm also not aware of any "standard" approach to making a dict
immutable as PEP 416 was rejected and PEP 603 is still under drafting stage.
I think it's best we keep this unfixed for now.
from fastapi-events.
I think it's not about this library, it's about our design. events should be immutable. as a developer you should try design to have immutable events. for example you can try pydantic frozen classes or frozen dataclass or something that guarantee immutable events.
one suggestion is to change library to only accept immutable events data :D
from fastapi-events.
Related Issues (20)
- Add GCP Cloud PubSub handler
- Catching exceptions of dispatched events HOT 1
- Trigger an event at startup HOT 3
- Add OpenTelemetry (OTEL) Support
- Providing AWS Credentials HOT 2
- Events are not received when dispatch() occurs in an asyncio.Task HOT 5
- Add Python 3.11 HOT 1
- Introduces NullHandler
- Support for Depends() HOT 8
- Starlette-Specific Test Cases Failing Since Starlette 0.24
- pydantic v2 import errors HOT 6
- pydantic v2 Warnings: The `dict` method is deprecated; use `model_dump` instead HOT 3
- Register event payload class and event in 1 HOT 8
- Update tox configuration to check compatibility with Python 3.12
- Pydantic models dumped to dict with deprecated method `dict` with pydantic v2 HOT 1
- Do not always dump pydantic models to dict
- docs: Update README with public API HOT 1
- TypeError with Synchronous Function in Dependencies When Using Local Handler HOT 1
- Feature Request: allow `dispatch` to take a `Callable` which generates the payload HOT 1
- OpenTelemetry breaks when events are Pydantic models
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastapi-events.