It would be beneficial if Pyramid were to raise a custom subclass of AttributeError. It could be something as generic as this:
class PyramidConfigurationError(AttributeError):
pass
This would be backwards compatible with existing code, but allow better control over detecting a non-configured session.
Right now, the exception string must be analyzed
try:
session = request.session
...
do things
...
except AttributeError as exc:
if exc.args[0].startswith("No session factory registered"):
do_something()
else:
do_something_else()
It would be preferable to catch it directly, like:
Feature Request
When there is a configuration issue, such as no session factory configured, Pyramid raises a standard AttributeError. See:
https://github.com/Pylons/pyramid/blob/68a6cb1dba7944f1e214ca62ce700e3f7ddf618d/src/pyramid/request.py#L189-L201
It would be beneficial if Pyramid were to raise a custom subclass of AttributeError. It could be something as generic as this:
This would be backwards compatible with existing code, but allow better control over detecting a non-configured session.
Right now, the exception string must be analyzed
It would be preferable to catch it directly, like:
I'm not sure how many other Pyramid components would benefit from this, so I understand the concern over its overall utility.