WiiLink24/food-server

Phantom Items (ID continuing to be referenced after deletion)

Closed this issue · 6 comments

So basically if you have a Item/Restaurant that has Issue you get a item that cant be fully deleted from the admin panel.

For example if you upload a .JPG as a Restaurant image it kinda creates but if you delete it the ID continues to be referenced.
(depending on the condition after you delete Restaurant ID 1 it stops showing on the admin panel, but ID 1 is still in the database. so the next Restaurant has a ID of 2 even though ID 1 should be gone)

kinda related to #8

Ok uhh i just found a really big issue. Outside of the Image type if you delete a Restaurant its not completely dropped in SQL (items included) @spotlightishere @sketchmaster2001

There are no exceptions or anything. It just does not drop the records in the DB

Ok uhh i just found a really big issue. Outside of the Image type if you delete a Restaurant its not completely dropped in SQL (items included) @spotlightishere @sketchmaster2001

Ok i was slightly wrong about this, its off of the database but its still counting upwards from ID 1 even though ID 1 was removed

Wait is this actually intended behavior 🤔 Im slightly confused

Auto-increment for primary columns is expected behavior - this lets the database manage identification without making us need to attempt for uniqueness, and allow indexing to occur :) It won't revert back to a primary value upon deletion of previous rows without manually modifying its value.

You can verify that this is present by looking at the default value for item_code, for example via \d item_list in psql:
Screenshot of \d item_list
This corresponds to the default behavior of SQLAlchemy, creating an auto-incrementing/sequenced key for the primary integer column:

food-server/models.py

Lines 78 to 79 in 39350da

class ItemList(db.Model):
item_code = db.Column(db.Integer, nullable=False, primary_key=True)

If items or menus related to the deleted restaurant persist, that is an issue. (However, this should not occur, as we specify a foreign key of shop_code for menus, and menu_code for items. If it does permit deletion, that's also a big issue!)

Ah ok I get it now! Thanks for explaining! @spotlightishere