Skip to content

Commit 23abadc

Browse files
Fix silent serialization failure when publishing non-JSON-serializable objects (#229)
* PubNub SDK 10.6.1 release. --------- Co-authored-by: PubNub Release Bot <120067856+pubnub-release-bot@users.noreply.github.com>
1 parent 5241c72 commit 23abadc

6 files changed

Lines changed: 60 additions & 7 deletions

File tree

.pubnub.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: python
2-
version: 10.6.0
2+
version: 10.6.1
33
schema: 1
44
scm: github.com/pubnub/python
55
sdks:
@@ -18,7 +18,7 @@ sdks:
1818
distributions:
1919
- distribution-type: library
2020
distribution-repository: package
21-
package-name: pubnub-10.6.0
21+
package-name: pubnub-10.6.1
2222
location: https://pypi.org/project/pubnub/
2323
supported-platforms:
2424
supported-operating-systems:
@@ -94,8 +94,8 @@ sdks:
9494
-
9595
distribution-type: library
9696
distribution-repository: git release
97-
package-name: pubnub-10.6.0
98-
location: https://github.com/pubnub/python/releases/download/10.6.0/pubnub-10.6.0.tar.gz
97+
package-name: pubnub-10.6.1
98+
location: https://github.com/pubnub/python/releases/download/10.6.1/pubnub-10.6.1.tar.gz
9999
supported-platforms:
100100
supported-operating-systems:
101101
Linux:
@@ -169,6 +169,11 @@ sdks:
169169
license-url: https://github.com/encode/httpx/blob/master/LICENSE.md
170170
is-required: Required
171171
changelog:
172+
- date: 2026-02-10
173+
version: 10.6.1
174+
changes:
175+
- type: bug
176+
text: "Fix silent serialization failure when publishing non-JSON-serializable objects."
172177
- date: 2026-01-29
173178
version: 10.6.0
174179
changes:

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 10.6.1
2+
February 10 2026
3+
4+
#### Fixed
5+
- Fix silent serialization failure when publishing non-JSON-serializable objects.
6+
17
## 10.6.0
28
January 29 2026
39

pubnub/enums.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class PNStatusCategory(Enum):
3939
PNInternalExceptionCategory = 17
4040
PNSubscriptionChangedCategory = 18
4141
PNConnectionErrorCategory = 19
42+
PNSerializationErrorCategory = 20
4243

4344

4445
class PNOperationType(object):

pubnub/utils.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from pubnub.models.consumer.common import PNStatus
1515
from pubnub.errors import PNERR_JSON_NOT_SERIALIZABLE
1616
from pubnub.exceptions import PubNubException
17+
from pubnub.models.consumer.pn_error_data import PNErrorData
1718

1819

1920
def get_data_for_user(data):
@@ -29,10 +30,17 @@ def get_data_for_user(data):
2930
def write_value_as_string(data):
3031
try:
3132
return json.dumps(data)
32-
except TypeError:
33-
raise PubNubException(
33+
except TypeError as e:
34+
exc = PubNubException(
35+
errormsg=str(e),
3436
pn_error=PNERR_JSON_NOT_SERIALIZABLE
3537
)
38+
status = PNStatus()
39+
status.category = PNStatusCategory.PNSerializationErrorCategory
40+
status.error = True
41+
status.error_data = PNErrorData(str(exc), exc)
42+
exc.status = status
43+
raise exc
3644

3745

3846
def url_encode(data):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name='pubnub',
5-
version='10.6.0',
5+
version='10.6.1',
66
description='PubNub Real-time push service in the cloud',
77
author='PubNub',
88
author_email='support@pubnub.com',
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from datetime import datetime
2+
3+
import pytest
4+
5+
from pubnub.enums import PNStatusCategory
6+
from pubnub.exceptions import PubNubAsyncioException
7+
from pubnub.models.consumer.common import PNStatus
8+
from pubnub.models.consumer.pn_error_data import PNErrorData
9+
from pubnub.pubnub_asyncio import PubNubAsyncio
10+
from tests.helper import pnconf_copy
11+
12+
13+
@pytest.mark.asyncio
14+
async def test_publish_non_serializable_returns_usable_error():
15+
pubnub = PubNubAsyncio(pnconf_copy())
16+
17+
result = await pubnub.publish().channel("ch1").message({
18+
"text": "Hello",
19+
"timestamp": datetime.now(),
20+
}).future()
21+
22+
assert isinstance(result, PubNubAsyncioException)
23+
assert result.is_error() is True
24+
assert isinstance(result.status, PNStatus)
25+
assert result.status.error is True
26+
assert result.status.category == PNStatusCategory.PNSerializationErrorCategory
27+
assert isinstance(result.status.error_data, PNErrorData)
28+
assert str(result) == (
29+
"Trying to publish not JSON serializable object: "
30+
"Object of type datetime is not JSON serializable"
31+
)
32+
33+
await pubnub.stop()

0 commit comments

Comments
 (0)