Skip to content

possible race condition: unicorn:model looses data when saved too quickly. #684

Open
@nerdoc

Description

@nerdoc

Especially when connections are slow, but even on localhost, the model is not fast enough to send the data to the backend, when the model saving method is called shortly after the last keypress. See this example:

class PersonView(UnicornView):
    person = Person.objects.none()

    def mount(self):
        self.person = Person.objects.get(
            pk=self.component_kwargs["pk"]
        )

    def save(self):
        self.person.save()
<div>
  <input type="text" unicorn:model="person.name" unicorn.keyup.enter="save">
</div>

When you run that component, write a longer string like "sdhfkjhdsfkjhkjdsf" and quickly press Enter, the saved model's name field will only contain approximately "sdhfkjhds".

I want to use unicorn for "inline" editing - a <input> replaces the text when in edit_mode and is saved automatically if in any of the input fields the user presses Enter. A quick and responsive UI is important, and data loss is very bad, in any case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions