@@ -79,3 +79,79 @@ async def test_uuid_type(db_conn: asyncpg.Connection):
7979 finally :
8080 # Cleanup
8181 await db_conn .execute ("DROP TABLE IF EXISTS people CASCADE" )
82+
83+
84+ @pytest .mark .asyncio
85+ async def test_uuid_empty_string_handling (db_conn : asyncpg .Connection ):
86+ """
87+ Test that empty strings in UUID columns are handled correctly.
88+
89+ This test verifies the fix for the issue where adding a UUID column
90+ to a table with existing rows would cause "Failed to parse UUID string:"
91+ error when querying. Empty strings stored in deeplake are treated as NULL.
92+
93+ Tests the exact scenario:
94+ 1. Create table without UUID column
95+ 2. Add UUID column (existing rows get NULL/empty values)
96+ 3. Query table (should not crash)
97+ 4. Insert row with NULL UUID
98+ 5. Query multiple times
99+ """
100+ assertions = Assertions (db_conn )
101+
102+ try :
103+ # Request 1: Create table uuid_test
104+ await db_conn .execute ("""
105+ CREATE TABLE uuid_test (
106+ id SERIAL PRIMARY KEY,
107+ name TEXT NOT NULL
108+ ) USING deeplake
109+ """ )
110+
111+ # Request 5: Query on uuid_test table
112+ rows = await db_conn .fetch (
113+ "SELECT * FROM (SELECT * FROM uuid_test ORDER BY id) LIMIT 20 OFFSET 0"
114+ )
115+ assert len (rows ) == 0 , f"Expected 0 rows, got { len (rows )} "
116+
117+ # Request 6: Add UUID column to uuid_test
118+ await db_conn .execute ("""
119+ ALTER TABLE uuid_test ADD COLUMN uu UUID
120+ """ )
121+
122+ # Request 8: Query uuid_test after schema change
123+ # This would previously crash with: ERROR: Failed to parse UUID string:
124+ rows = await db_conn .fetch (
125+ "SELECT * FROM (SELECT * FROM uuid_test ORDER BY id) LIMIT 20 OFFSET 0"
126+ )
127+ assert len (rows ) == 0 , f"Expected 0 rows after adding UUID column, got { len (rows )} "
128+
129+ # Request 9: Insert row with empty name and NULL UUID
130+ await db_conn .execute ("""
131+ INSERT INTO uuid_test (name, uu) VALUES ('', NULL)
132+ """ )
133+
134+ # Request 11: Query uuid_test after insert
135+ rows = await db_conn .fetch (
136+ "SELECT * FROM (SELECT * FROM uuid_test ORDER BY id) LIMIT 20 OFFSET 0"
137+ )
138+ assert len (rows ) == 1 , f"Expected 1 row after insert, got { len (rows )} "
139+ assert rows [0 ]['uu' ] is None , "UUID should be NULL"
140+
141+ # Request 12: Query uuid_test again
142+ rows = await db_conn .fetch (
143+ "SELECT * FROM (SELECT * FROM uuid_test ORDER BY id) LIMIT 20 OFFSET 0"
144+ )
145+ assert len (rows ) == 1 , f"Expected 1 row, got { len (rows )} "
146+
147+ # Request 13: Query uuid_test again
148+ rows = await db_conn .fetch (
149+ "SELECT * FROM (SELECT * FROM uuid_test ORDER BY id) LIMIT 20 OFFSET 0"
150+ )
151+ assert len (rows ) == 1 , f"Expected 1 row, got { len (rows )} "
152+
153+ print ("✓ Test passed: UUID empty string handling works correctly" )
154+
155+ finally :
156+ # Cleanup
157+ await db_conn .execute ("DROP TABLE IF EXISTS uuid_test CASCADE" )
0 commit comments