# When xblock.save() method is called to store data from \_dirty\_fields?

**URL:** <https://discuss.openedx.org/t/when-xblock-save-method-is-called-to-store-data-from-dirty-fields/4307>\
**Category:** Development\
**Created:** [February 19, 2021, 1:58pm UTC](https://discuss.openedx.org/t/when-xblock-save-method-is-called-to-store-data-from-dirty-fields/4307 "2021-02-19T13:58:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vikrant](https://avatars.discourse-cdn.com/v4/letter/v/cc9497/32.png) [@vikrant](https://discuss.openedx.org/u/vikrant)\
**Post date:** [February 19, 2021, 1:58pm UTC](https://discuss.openedx.org/t/when-xblock-save-method-is-called-to-store-data-from-dirty-fields/4307/1 "2021-02-19T13:58:11Z")

</div>

I am trying to understand how data gets reflected in database on modifying default ‘count’ field.

I reached the point where modified value is stored in cache and marked as dirty to store in database when xblock is saved.

But I’m unable to understand exactly at what point xblock.save() method is called?

Will be a great help if anyone can guide me on this.

---

<div class="post-metadata">

**Author:** ![braden](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/braden/32/46_2.png) [@braden](https://discuss.openedx.org/u/braden)\
**Post date:** [February 19, 2021, 10:31pm UTC](https://discuss.openedx.org/t/when-xblock-save-method-is-called-to-store-data-from-dirty-fields/4307/2 "2021-02-19T22:31:26Z")

</div>

> [@vikrant](#):
>
> But I’m unable to understand exactly at what point xblock.save() method is called?

Here, when you `render` any view like `student_view`: [https://github.com/edx/XBlock/blob/1af0c970c20895276d75fc26501f60c98f434e3e/xblock/runtime.py#L828-L829](https://github.com/edx/XBlock/blob/1af0c970c20895276d75fc26501f60c98f434e3e/xblock/runtime.py#L828-L829)

Rendering any view calls `block.render()` which calls `block.runtime.render()` which calls `block.save()`, as you can see.

And here, when you call any handler: [https://github.com/edx/XBlock/blob/1af0c970c20895276d75fc26501f60c98f434e3e/xblock/runtime.py#L1069-L1070](https://github.com/edx/XBlock/blob/1af0c970c20895276d75fc26501f60c98f434e3e/xblock/runtime.py#L1069-L1070)

By the way, if you need to find something like this in the future, just edit [the file where save() is](https://github.com/edx/XBlock/blob/7e88177bf55c3a5e3ffe0f16fbf3a0a535ed7332/xblock/mixins.py#L242-L251) and make it throw an exception. Then view your XBlock, get the exception, and see the traceback from the exception to see how the code was called.

---

<div class="post-metadata">

**Author:** ![vikrant](https://avatars.discourse-cdn.com/v4/letter/v/cc9497/32.png) [@vikrant](https://discuss.openedx.org/u/vikrant)\
**Post date:** [February 20, 2021, 5:18pm UTC](https://discuss.openedx.org/t/when-xblock-save-method-is-called-to-store-data-from-dirty-fields/4307/3 "2021-02-20T17:18:34Z")

</div>

@braden Thank you so much… You have been a great help always…
