Coverage for adhoc-cicd-odoo-odoo / odoo / exceptions.py: 71%
28 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-09 18:05 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-09 18:05 +0000
1"""The Odoo Exceptions module defines a few core exception types.
3Those types are understood by the RPC layer.
4Any other exception type bubbling until the RPC layer will be
5treated as a 'Server error'.
6"""
9class UserError(Exception):
10 """Generic error managed by the client.
12 Typically when the user tries to do something that has no sense given the current
13 state of a record.
14 """
15 http_status = 422 # Unprocessable Entity
17 def __init__(self, message):
18 """
19 :param message: exception message and frontend modal content
20 """
21 super().__init__(message)
24class RedirectWarning(Exception):
25 """ Warning with a possibility to redirect the user instead of simply
26 displaying the warning message.
28 :param str message: exception message and frontend modal content
29 :param int action_id: id of the action where to perform the redirection
30 :param str button_text: text to put on the button that will trigger
31 the redirection.
32 :param dict additional_context: parameter passed to action_id.
33 Can be used to limit a view to active_ids for example.
34 """
35 def __init__(self, message, action, button_text, additional_context=None):
36 super().__init__(message, action, button_text, additional_context)
39class AccessDenied(UserError):
40 """Login/password error.
42 .. note::
44 Traceback only visible in the logs.
46 .. admonition:: Example
48 When you try to log with a wrong password.
49 """
50 http_status = 403 # Forbidden
52 def __init__(self, message="Access Denied"):
53 super().__init__(message)
54 self.suppress_traceback() # must be called in `except`s too
56 def suppress_traceback(self):
57 """
58 Remove the traceback, cause and context of the exception, hiding
59 where the exception occured but keeping the exception message.
61 This method must be called in all situations where we are about
62 to print this exception to the users.
64 It is OK to leave the traceback (thus to *not* call this method)
65 if the exception is only logged in the logs, as they are only
66 accessible by the system administrators.
67 """
68 self.with_traceback(None)
69 self.traceback = ('', '', '')
71 # During handling of the above exception, another exception occurred
72 self.__context__ = None
74 # The above exception was the direct cause of the following exception
75 self.__cause__ = None
77class AccessError(UserError):
78 """Access rights error.
80 .. admonition:: Example
82 When you try to read a record that you are not allowed to.
83 """
84 http_status = 403 # Forbidden
87class CacheMiss(KeyError):
88 """Missing value(s) in cache.
90 .. admonition:: Example
92 When you try to read a value in a flushed cache.
93 """
95 def __init__(self, record, field):
96 super().__init__("%r.%s" % (record, field.name))
99class MissingError(UserError):
100 """Missing record(s).
102 .. admonition:: Example
104 When you try to write on a deleted record.
105 """
106 http_status = 404 # Not Found
109class LockError(UserError):
110 """Record(s) could not be locked.
112 .. admonition:: Example
114 Code tried to lock records, but could not succeed.
115 """
116 http_status = 409 # Conflict
119class ValidationError(UserError):
120 """Violation of python constraints.
122 .. admonition:: Example
124 When you try to create a new user with a login which already exist in the db.
125 """
128class ConcurrencyError(Exception):
129 """
130 Signal that two concurrent transactions tried to commit something
131 that violates some constraint. Signal that the transaction that
132 failed should be retried after a short delay, see
133 :func:`~odoo.service.model.retrying`.
135 This exception is low-level and has very few use cases, it should
136 only be used if all alternatives are deemed worse.
137 """