Skip to content

Extra returning fields in UpdateRequest.apply #730

Open
@kigawas

Description

@kigawas

Sometimes there is need to retrieve some server updated fields in the in-memory instance:

user = await User.create()
print(user.updated_at)  #  updated_at_1
await user.update(balance=User.balance + 100).apply()
print(user.updated_at)  # updated_at_2, and it should not be equal to updated_at_1

Unfortunately, gino only retrieves updated fields like

        # in `crud.py`
        clause = (
            type(self._instance)
            .update.where(
                self._locator,
            )
            .values(
                **self._instance._get_sa_values(values),
            )
            .returning(
                *[getattr(cls, key) for key in values], # <- only updated values will return
            )
            .execution_options(**opts)
        )

I'd like to specify some "extra fields" here, maybe in this form:

user = await User.create()
print(user.updated_at)  #  updated_at_1
await user.update(balance=User.balance + 100).apply(extra_returning_fields=['updated_at'])
print(user.updated_at)  # expected: updated_at_2 > updated_at_1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions