diff --git a/asyncpg/protocol/coreproto.pyx b/asyncpg/protocol/coreproto.pyx index 8e34014e..d5936c7a 100644 --- a/asyncpg/protocol/coreproto.pyx +++ b/asyncpg/protocol/coreproto.pyx @@ -675,7 +675,7 @@ cdef class CoreProtocol: WriteBuffer msg msg = WriteBuffer.new_message(b'p') - msg.write_bytestring(self.password.encode(self.encoding)) + msg.write_bytestring((self.password or '').encode(self.encoding)) msg.end_message() return msg diff --git a/tests/test_connect.py b/tests/test_connect.py index 839c3dcf..e00c7b6c 100644 --- a/tests/test_connect.py +++ b/tests/test_connect.py @@ -270,6 +270,11 @@ async def test_auth_password_cleartext(self): user='password_user', password='wrongpassword') + async def test_auth_password_cleartext_without_password(self): + with self.assertRaises(asyncpg.InvalidPasswordError): + await self._try_connect( + user='password_user', password=lambda: None) + async def test_auth_password_cleartext_callable(self): def get_correctpassword(): return CORRECT_PASSWORD