Skip to content

Commit

Permalink
Update warning when invalid delivery is set
Browse files Browse the repository at this point in the history
  • Loading branch information
imjoehaines committed Jan 24, 2024
1 parent 168b0a8 commit dd361ac
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
19 changes: 19 additions & 0 deletions bugsnag/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,25 @@ def delivery(self):
def delivery(self, value):
if hasattr(value, 'deliver') and callable(value.deliver):
self._delivery = value

# deliver_sessions is _technically_ optional in that if you disable
# session tracking it will never be called
# this should be made mandatory in the next major release
if (
hasattr(value, 'deliver_sessions') and
callable(value.deliver_sessions)
):
parameter_names = value.deliver_sessions.__code__.co_varnames

if 'options' not in parameter_names:
warnings.warn(
'delivery.deliver_sessions should accept an ' +
'"options" parameter to allow for synchronous ' +
'delivery, sessions may be lost when the process ' +
'exits',
DeprecationWarning
)

else:
message = ('delivery should implement Delivery interface, got ' +
'{0}. This will be an error in a future release.')
Expand Down
21 changes: 21 additions & 0 deletions tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ class BadDelivery(object):
def deliv(self, *args, **kwargs):
pass

class OkDelivery:
def deliver(self, *args, **kwargs):
pass

def deliver_sessions(self, config, payload):
pass

class GoodDelivery(object):
def deliver(self, *args, **kwargs):
pass
Expand All @@ -213,6 +220,20 @@ def deliver(self, *args, **kwargs):
assert len(record) == 1
assert c.delivery == good

with pytest.warns(DeprecationWarning) as record:
ok = OkDelivery()

c.configure(delivery=ok)

assert len(record) == 1
assert str(record[0].message) == (
'delivery.deliver_sessions should accept an "options" ' +
'parameter to allow for synchronous delivery, sessions ' +
'may be lost when the process exits'
)

assert c.delivery == ok

def test_validate_hostname(self):
c = Configuration()
with pytest.warns(RuntimeWarning) as record:
Expand Down

0 comments on commit dd361ac

Please sign in to comment.