# \`\_save\_values\` side-effect

**URL:** https://discuss.tryton.org/t/save-values-side-effect/3027
**Category:** Ideas
**Created:** [July 15, 2020, 8:33am UTC](https://discuss.tryton.org/t/save-values-side-effect/3027 "2020-07-15T08:33:32Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![JCavallo](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/j/48db29/32.png) [@JCavallo](https://discuss.tryton.org/u/JCavallo)
#### Post date: [July 15, 2020, 8:33am UTC](https://discuss.tryton.org/t/save-values-side-effect/3027/1 "2020-07-15T08:33:32Z")

</div>

Hi Tryton,

I have always wondered about a behavior of `_save_values` in the following case:

```auto
address = Pool().get('party.address')()
address.party = Pool().get('party.party')()

_ = address._save_values

# At this point, address.party is saved, even though no "save" call was
# actually made

```

For information, the relevant line is here : [https://hg.tryton.org/trytond/file/tip/trytond/model/modelstorage.py#l1606](https://hg.tryton.org/trytond/file/tip/trytond/model/modelstorage.py#l1606)

- I understand why it is necessary to save the party to “generate” the `_save_values` for the address
- I also understand that `_save_values` is not really meant to be used apart from when `save` is called, however I have found it very useful in some technical cases

Anyway, I think this behavior is strange, and would like to know the rationale behind it

- `_save_values` “looks a lot” like it is a “readonly” function (because of its name, and how it is a property), and saving object is a really non-obvious (and dangerous) side-effect
- The sneaky saving is not really efficient (in the case of a batch save)

I would really like to know how much of this is intended. I would assume it dates back to the Active Record migration, to maintain compatibility with some previous code.

Also, I think that when this is called outside of actually “saving” (meaning a direct call from inside `save`), it should probably be an error, because it will usually never be a desired behavior.

Thanks!

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [July 15, 2020, 9:39am UTC](https://discuss.tryton.org/t/save-values-side-effect/3027/2 "2020-07-15T09:39:11Z")

</div>

I agree that this side-effect is not clean.

> [@JCavallo](#):
>
> I would really like to know how much of this is intended. I would assume it dates back to the Active Record migration, to maintain compatibility with some previous code.

I do not think it is to maintain any backward compatibility because such feature did not exist before.  
But I guess it was coded like that because it is easy.

> [@JCavallo](#):
>
> Also, I think that when this is called outside of actually “saving” (meaning a direct call from inside `save` ), it should probably be an error, because it will usually never be a desired behavior.

Yes, I think a good improvement would be to move this save call out of `_save_values` and put it in `save()`. So `_save_values` could raise an error if the target is not a store record.
