i was sure i am already checking the form to create a new item.
The problem i was facing why the log show me that i am creating ID on number 1. Note that on campaign.py.DB.create() the sql code was showing its was using INSERT so i am sure its creating ID and without knowing the ID number so its must generate a new one. Thats the confuse part because its said i am creating duplicate item on unique key and that is "ID"
I am found a bug and i am already fix it. I am still wondering what i just do and the true meaning of it. Take a look on this test https://travis-ci.org/eisenhaus335/wikilabels/builds/317939040. My test_campaign_create() and test_campaign_get() is passed. Module that i am using is https://github.com/eisenhaus335/wikilabels/blob/a8b87f69d2b853509995ccc890b61c0df77c10df/wikilabels/tests/test_database.py here.
My problem was the id is not re indexed as you can see on chat history. I am worry this solution is not optimum and eating performance but you can suggest what i can improve
My solution was using cursor.execute("SELECT setval('campaign_id_seq', (SELECT MAX(id) FROM campaign)+1)") to create method on campaign module. I worry again this might result on eat performance and might result new bug
Even though performance is not the case in here because the module is used ~once a week in prod, that idea seems like a very bad practice that should be avoided, if it was only on test code, it would be okay-ish but I don't recommend doing this in production code.
These are options:
- Have you tried ignore errors when creating the campaign? It might be created before and we might have a unique index preventing duplicates.
- If your fix only needs a schema change to add an index, do it, make a patch and I review it :)