Skip to content

Commit cea05ee

Browse files
Fix field_name check order when creating a field in a table.
1 parent 089ba4c commit cea05ee

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/SSD/core/database.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,20 +253,23 @@ def __new_fields(self,
253253
field_name, field_type = field[0], field[1]
254254
field_default = '_null_' if len(field) == 2 else field[2]
255255

256-
# As peewee.Model creates a new attribute named field_name, check that this attribute does not exist
257-
if field_name in [m[0] for m in getmembers(table)]:
258-
raise ValueError(f"Tried to create a field '{field_name}' in the Table '{table_name}'. "
259-
f"You are not allowed to create a field with this name, please rename it.")
260-
261256
# Extend the Table
262257
if field_name not in table.fields():
258+
259+
# As peewee.Model creates a new attribute named field_name, check that this attribute does not exist
260+
if field_name in [m[0] for m in getmembers(table)]:
261+
raise ValueError(f"Tried to create a field '{field_name}' in the Table '{table_name}'. "
262+
f"You are not allowed to create a field with this name, please rename it.")
263+
263264
# FK
264265
if type(field_type) == str:
265266
if (fk_table_name := self.make_name(field_type)) not in self.__tables.keys():
266267
raise ValueError(f"Cannot create the ForeignKey '{fk_table_name}' since this Table does not"
267268
f"exists. Created Tables so far: {self.__tables.keys()}")
268269
table.extend_fk(self.__tables[fk_table_name], field_name)
269270
self.__fk[table_name][field_name] = fk_table_name
271+
272+
# Standard field
270273
else:
271274
table.extend(field_name, field_type, field_default)
272275

0 commit comments

Comments
 (0)