rathoud96
I am working with commanded by @slashdotdash. Recently I encountered an issue where my aggregate’s state was different than my projection.
For example the aggregate state is %Aggregate.Example{is_valid: false} and my projection is %Projection.Example{is_valid: true}
Now I am stuck on how to sync them or is there a way the state can be updated?
Thanks
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex











Showing Posts 1 to 7- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
tcoopman
I’m lacking a bit of context to give a good response.
Do you mean your projection in production has a bug so that it’s state is wrong? Did you forget to handle an event? Or something else?
If it’s a bug in your projection, the default way to solve this would be to fix the bug, deploy it and then replay the eventstream.
rathoud96
Hello, @tcoopman thanks for the quick response.
My projection is correct but my aggregate state is incorrect.
tcoopman
Do you know why they have a different internal state? Did you find the bug?
In event sourced systems your aggragate is the thing that makes decisions.
Syncing is not something we want to do manually. We always look at the stream of events. They are the source of truth.
Depending on the kind of bug you made, you can either rebuild the aggregate state:
https://github.com/commanded/commanded/blob/master/guides/Aggregates.md#rebuilding-an-aggregate-snapshot
Or send in a compensating command to the aggregate. That means you need to implement that on the aggregate, and then make sure that it uses the command to fix it’s internal state.
rathoud96
I could not find the bug. In the event stream as well i just have error logs but those aren’t helpful.
I tried to delete the event stream but now if i run the same command again it says
command_uuidnot found.I am pretty new with commanded that’s why having difficulty figuring out the issue.
tcoopman
Do you have some code that you can share so we can take a look at it?
rathoud96
It would be difficult to share the sample code, but I will try to explain in a more detail.
I have a table ‘books’. It looks something like this
And my aggregate looks looking like this
Now before the recent change, the
is_publishedwas true for aggregate as well but now after I put a validation for the author_id it’s giving me the wrong state in aggregate.What the validation is
if author_id is in DB then the 'is_published: true' else 'is_published: false'And the above validation would work only when we insert or update the operation.
Now I am not getting why this validation would change the
aggregatestate.After adding the validation I didn’t do any insert or update.
tcoopman
On my phone, so I’ll do my best to respond.
I’m going to take a step back from commanded and talk about event sourcing in general for a moment.
In event sourcing an aggregate takes a list of events (it’s own history) and a command and it makes a decision. That decision is communicated by returning one or more events.
The aggregate should be pure. Meaning it should make the decision only based on the information in the history of the events and the command. It should do no queries or other side effects to make a decision.
I write should. I mean I strongly suggest doing it that way. It will give you easier to understand code. Easier to test code,…
Looking at your code it looks like you’re doing a query in the aggregate. From a design perspective I would try to extract that.
It’s not clear though where you’re doing the query in the aggregate. Is it when making the decision? So where you handle the command? Or is it in the apply function?
If it’s in the apply function it is definitely wrong. Your apply function MUST be pure.
If it’s in the code making a decision. The only thing I can imply is that at the time of the command the author was not in the DB. I would expect a different event though depending on if the author is in or not, so the projection should follow and have the same information.
Hopefully this makes sense. If not let me know.