Skip to content

Commit a5ffa1f

Browse files
fix: raise error when table declaration fails due to permissions
Previously, AccessError during table declaration was silently swallowed, causing tables with cross-schema foreign keys to fail without any feedback when the user lacked REFERENCES privilege. Now: - If table already exists: suppress error (idempotent declaration) - If table doesn't exist: raise AccessError with helpful message about CREATE and REFERENCES privileges Closes #1161 Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent c1b36f0 commit a5ffa1f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/datajoint/table.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,15 @@ def declare(self, context=None):
148148
try:
149149
self.connection.query(sql)
150150
except AccessError:
151-
# skip if no create privilege
152-
return
151+
# Only suppress if table already exists (idempotent declaration)
152+
# Otherwise raise - user needs to know about permission issues
153+
if self.is_declared:
154+
return
155+
raise AccessError(
156+
f"Cannot declare table {self.full_table_name}. "
157+
f"Check that you have CREATE privilege on schema `{self.database}` "
158+
f"and REFERENCES privilege on any referenced parent tables."
159+
) from None
153160

154161
# Populate lineage table for this table's attributes
155162
self._populate_lineage(primary_key, fk_attribute_map)

0 commit comments

Comments
 (0)