Skip to content
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

setattr should happen only if ConcurentUpdate is not raised #12

Open
YasenKalinin opened this issue Jan 22, 2019 · 0 comments
Open

setattr should happen only if ConcurentUpdate is not raised #12

YasenKalinin opened this issue Jan 22, 2019 · 0 comments

Comments

@YasenKalinin
Copy link

in Versioned Mixin:
If versioned model instance is in transaction atomic(): and if setattr( instance, version_field, new_version) happens and ConcurrentUpdate is raised, python object is changed, but db is reverted. So: setattr should happen only if not raising ConcurrentUpdate
Maybe:
`

    to_change = {}
    for i, value_tuple in enumerate(values):
        if isinstance(value_tuple[0], VersionField):
            assert old_version == value_tuple[2]
            values[i] = (
                value_tuple[0],
                value_tuple[1],
                value_tuple[2] + 1,
            )
            to_change[ version_field.attname] = old_version + 1
            #setattr(self, version_field.attname, old_version + 1)

    updated = super(VersionedMixin, self)._do_update(
        base_qs=base_qs.filter(**{version_field.attname: old_version}),
        using=using,
        pk_val=pk_val,
        values=values,
        update_fields=update_fields if values else None,  # Make sure base_qs is always checked
        forced_update=forced_update
    )

    if not updated and base_qs.filter(pk=pk_val).exists():
        raise ConcurrentUpdate
    
    for vf_attname, new_version in to_change.items():
        setattr( self, vf_attname, new_version)
    
    return updated

`

@YasenKalinin YasenKalinin changed the title setattr should happen only if updated setattr should happen only if ConcurentUpdate is not raised Jan 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant