Skip to content

Commit

Permalink
component: add RegistryNotReadyError
Browse files Browse the repository at this point in the history
Sounds valueable to have a specific type of error
rather than a KeyError when something break
because no registry is ready.
  • Loading branch information
simahawk committed Sep 2, 2024
1 parent a5d9028 commit a93344b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 8 additions & 5 deletions component/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from odoo import models
from odoo.tools import LastOrderedSet, OrderedSet

from .exception import NoComponentError, SeveralComponentError
from .exception import NoComponentError, RegistryNotReadyError, SeveralComponentError

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -252,14 +252,17 @@ def __init__(
dbname = self.env.cr.dbname
try:
self.components_registry = _component_databases[dbname]
except KeyError:
_logger.error(
except KeyError as exc:
msg = (
"No component registry for database %s. "
"Probably because the Odoo registry has not been built "
"yet.",
"yet."
)
_logger.error(
msg,
dbname,
)
raise
raise RegistryNotReadyError(msg) from exc
self._propagate_kwargs = ["collection", "model_name", "components_registry"]
for attr_name, value in kwargs.items():
setattr(self, attr_name, value)
Expand Down
4 changes: 4 additions & 0 deletions component/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ class NoComponentError(ComponentException):

class SeveralComponentError(ComponentException):
"""More than one component have been found"""


class RegistryNotReadyError(ComponentException):
"""Component registry not ready yet for given DB."""

0 comments on commit a93344b

Please sign in to comment.