Skip to content

Fix AttributeError when executing empty or comment-only scripts#1303

Open
veeceey wants to merge 1 commit into
MagicStack:masterfrom
veeceey:fix/issue-1259-empty-script-error
Open

Fix AttributeError when executing empty or comment-only scripts#1303
veeceey wants to merge 1 commit into
MagicStack:masterfrom
veeceey:fix/issue-1259-empty-script-error

Conversation

@veeceey

@veeceey veeceey commented Feb 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fixes AttributeError: 'NoneType' object has no attribute 'decode' when executing empty or comment-only scripts
  • Adds null check for result_status_msg before attempting to decode
  • Includes test cases for empty scripts, comment-only scripts, and whitespace-only scripts

Issue

Fixes #1259

When executing a PostgreSQL script that contains only comments (e.g., -- hello) or is empty, PostgreSQL returns no result status message. The code attempted to call .decode() on None, causing an AttributeError.

Changes

  • Modified asyncpg/protocol/protocol.pyx to check if result_status_msg is not None before decoding
  • Added comprehensive test cases in tests/test_execute.py to verify the fix

Test plan

  • Added test case for comment-only script ('-- hello')
  • Added test case for whitespace-only script (' ')
  • Added test case for empty script ('')
  • All tests verify that the execute() call returns None instead of raising an error

This is a natural behavior where executing a script with only comments should be a no-op, which is useful when commenting out migration script contents during development.

When executing a script that contains only comments or is empty,
PostgreSQL returns no result status message. This caused an
AttributeError when trying to decode None.

Fixes MagicStack#1259
@veeceey

veeceey commented Feb 19, 2026

Copy link
Copy Markdown
Contributor Author

Friendly ping - any chance someone could take a look at this when they get a chance? Happy to make any changes if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant