Logo video2dn
  • Сохранить видео с ютуба
  • Категории
    • Музыка
    • Кино и Анимация
    • Автомобили
    • Животные
    • Спорт
    • Путешествия
    • Игры
    • Люди и Блоги
    • Юмор
    • Развлечения
    • Новости и Политика
    • Howto и Стиль
    • Diy своими руками
    • Образование
    • Наука и Технологии
    • Некоммерческие Организации
  • О сайте

Скачать или смотреть Ensure Your Odoo Custom Logging is Exempt from Rollbacks!

  • vlogize
  • 2025-05-26
  • 2
Ensure Your Odoo Custom Logging is Exempt from Rollbacks!
How would I exclude an Odoo custom logging model from rollbacks?odoo
  • ok logo

Скачать Ensure Your Odoo Custom Logging is Exempt from Rollbacks! бесплатно в качестве 4к (2к / 1080p)

У нас вы можете скачать бесплатно Ensure Your Odoo Custom Logging is Exempt from Rollbacks! или посмотреть видео с ютуба в максимальном доступном качестве.

Для скачивания выберите вариант из формы ниже:

  • Информация по загрузке:

Cкачать музыку Ensure Your Odoo Custom Logging is Exempt from Rollbacks! бесплатно в формате MP3:

Если иконки загрузки не отобразились, ПОЖАЛУЙСТА, НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если у вас возникли трудности с загрузкой, пожалуйста, свяжитесь с нами по контактам, указанным в нижней части страницы.
Спасибо за использование сервиса video2dn.com

Описание к видео Ensure Your Odoo Custom Logging is Exempt from Rollbacks!

Discover how to create a custom logging model in Odoo that remains unaffected by transaction rollbacks, ensuring your logs always capture important information.
---
This video is based on the question https://stackoverflow.com/q/70700596/ asked by the user 'Aaron Beaudoin' ( https://stackoverflow.com/u/14953293/ ) and on the answer https://stackoverflow.com/a/70702434/ provided by the user 'Aaron Beaudoin' ( https://stackoverflow.com/u/14953293/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions.

Visit these links for original content and any more details, such as alternate solutions, latest updates/developments on topic, comments, revision history etc. For example, the original title of the Question was: How would I exclude an Odoo custom logging model from rollbacks?

Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/l...
The original Question post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license, and the original Answer post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license.

If anything seems off to you, please feel free to write me at vlogize [AT] gmail [DOT] com.
---
How to Exclude Your Odoo Custom Logging Model from Rollbacks

When working with Odoo, one might find the need to create a custom logging model. The challenge arises when you want this logging model to remain unaffected by the typical transaction rollback behavior. In other words, you desire your logs to be saved even if an exception occurs later in your code. This requirement often surfaces when dealing with critical operations where missing log entries could mean lost insights or debugging information.

In this guide, we’ll explore how to achieve this goal, ensuring your custom logs are intact regardless of subsequent exceptions. Let’s dive into the solution in detail.

The Need for Custom Logging

Imagine you have a model in Odoo that performs several operations, and during its execution, something goes wrong, triggering an exception. By default, Odoo rolls back the database transaction to maintain data integrity. However, this rollback would also erase any log entries made up to that point, which defeats the purpose of logging critical events. Therefore, we need a way to ensure these logs are written independently of the transaction state.

Implementing the Solution

We can create a logging method that utilizes a separate database cursor for logging entries—this is key to circumventing Odoo's rollback behavior. Here's how to approach the solution in detail:

Step 1: Define the Logging Method with a Separate Cursor

Here’s how you can define your add_entry() method within your custom logging model:

[[See Video to Reveal this Text or Code Snippet]]

Key Points:

Flush Pending Operations: Before creating a log entry, we ensure to flush any pending operations. This preparation is essential to avoid exceptions during the commit phase of our separated cursor.

Separate Database Cursor: By using with registry(self.env.cr.dbname).cursor() as cr, we create a cursor that operates independently of the main transaction. This allows the log entry to be committed no matter what happens afterward.

Step 2: Return the Log Entry Safely

It’s important to handle the returned log record correctly:

Instead of returning the record directly from the create() method, we maintain the record ID and utilize self.browse(record.id) to fetch the record in the current environment with an active cursor. This ensures that we are interacting with the right environment object.

Important Note on Performance

Although we want to avoid performance issues, the flushing of data in the database might incur some overhead. Keep this in consideration when implementing the logging mechanism. Testing and optimizing your code is essential to ensure it meets performance expectations while retaining robustness.

Important Edits and Observations

After some experimentation, a critical edit was made to add the self.flush() line before the cursor operation. This tweak was necessary due to exceptions arising when committing data; something that Odoo’s underlying mechanisms can trigger. It’s important to continuously update your implementation based on your coding experience, as shown here.

Conclusion

In conclusion, creating a custom logging model in Odoo that is exempt from rollback behavior can be achieved with a bit of careful coding. By introducing a separate database cursor and managing record creation adequately, you can ensure that your logs are safely stored regardless of subsequent exceptions in your code.

Feel free to implement these strategies in your Odoo development journey. Also, share your improvements or alternative solutions in the comments below. Happy coding!

Комментарии

Информация по комментариям в разработке

Похожие видео

  • О нас
  • Контакты
  • Отказ от ответственности - Disclaimer
  • Условия использования сайта - TOS
  • Политика конфиденциальности

video2dn Copyright © 2023 - 2025

Контакты для правообладателей [email protected]