Skip to content

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

Open
veeceey wants to merge 1 commit intoMagicStack: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 intoMagicStack:masterfrom
veeceey:fix/issue-1259-empty-script-error

Conversation

@veeceey
Copy link

@veeceey veeceey commented Feb 8, 2026

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"AttributeError: 'NoneType' object has no attribute 'decode'" when executing empty script

1 participant