question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why repository does not found entity_id ?

See original GitHub issue

Hello,

I’m trying to work with eventsourcing library and for the simple example :

class Ingredient(AggregateRoot):
    class Event(AggregateRoot.Event):
        pass

    @classmethod
    def create(cls, name: str):
        return cls.__create__(name=name)

    class Created(Event, AggregateRoot.Created):
        pass

    def __init__(self, name: str, **kwargs):
        super().__init__(**kwargs)

        self.name = name

    def __repr__(self):
        return f"<Ingredient (id={self.id} name={self.name}) object at {hex(id(self))}>"


class Ingredients(ProcessApplication):
    @applicationpolicy
    def policy(self, repository, event):
        pass

    @staticmethod
    def create_ingredient(name: str):
        return Ingredient.create(name)

When i try to execute the following code from a runner:

with SingleThreadedRunner(system, infrastructure_class=PopoApplication) as runner:
    ingredient = runner.system.ingredients.create_ingredient(name="Test")
    print(ingredient.id in runner.system.ingredients.repository)

the print returns “False” (the ingredient is not persisted ?) where i’m doing something wrong ?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
ghostcommented, Oct 2, 2019

It works now, thank you. You did a great work !

I will open other issues if I have others questions.

Note: https://eventsourcing.readthedocs.io/en/stable/topics/process.html#processes is not up to date 😃

0reactions
johnbywatercommented, Oct 2, 2019

@JeanDeuns I think it’s up to date? There’s a small difference between the code that you linked to and the code you wrote. The “general rule” is that the __save__() method should be called on new or changed aggregates, except when they are created or updated within a process application policy (so that the domain events can be persisted atomically with the tracking and notification information). In particular, in that bit of the documentation, there is a command method on the Commands process application which does call __save__(). The other applications create and update aggregates with their process application policy, and so correctly do not call __save__(). It’s a subtle aspect perhaps, but it reflects the atomicity of the recording. __save__() is atomic only for the new domain events of a single aggregate. Hope that helps 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

I can't get an entity ID in spring boot - Stack Overflow
You look to be trying to get your id from the user passed to you in the post request: actual_user_id = user.getId();.
Read more >
Entity not creating id properly · Issue #313 · JetBrains/Exposed
I have the following table and entity: object Destinations : IdTable () { override val id ... entityId() val created = long("created").
Read more >
CrudRepository (Spring Data Core 3.0.0 API)
Parameters: id - must not be null. Returns: the entity with the given id or Optional#empty() if none found. Throws: IllegalArgumentException - if...
Read more >
StorageTxImpl (org.sonatype.nexus:nexus-repository 3.19.1 ...
Gets a component by id, regardless of which bucket it resides in, or null if not found. Component · findComponentInBucket(org.sonatype.nexus.common.entity.
Read more >
Spring Data - CrudRepository save() Method - Baeldung
CrudRepository is a Spring Data interface for generic CRUD operations on a ... Here we specify the entity's class and the entity id's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found