Похожие чаты

Всем привет, такая проблема, у меня есть уникальность по полю. В

одной транзакции я сначала удаляю сущность
session.delete(obj)

А после создаю с таким же уникальным параметром
session.add(obj)

И когда делаю
session.commit()
То падает ошибка с тем, что такие данные уже есть. Если между удалением и созданием сделать
session.flush() то все ок

Есть другие решения кроме flush?

7 ответов

7 просмотров

Можешь попробовать session.execute(delete(obj).where(obj.id == id))

Matvei-Bekishev Автор вопроса
Fred Bernardo
Можешь попробовать session.execute(delete(obj).whe...

Но хотелось бы решение с session.delete

Matvei Bekishev
Но хотелось бы решение с session.delete

session.delete удаляет из сессии, не из бд

тебе в базу нужно отправить данные и обновить стейт в сессии. других решений нет, т.к. сессия хранить в себе записи по pk

Matvei-Bekishev Автор вопроса
Matvei-Bekishev Автор вопроса

Логично, и это я понимаю. Но и падает в момент комита. И наверное тут логичнее было бы если бы в комите были бы действия в таком же порядке как и работа с сессией

Похожие вопросы

Обсуждают сегодня

@LGCYMan @JustinKKW Q/A List 1. this part confuses me on #8: "From there, a bridge between erc20 LGXY and erc20 LGXY will be out once that swap is closed." does this mean ...
Sig | LGXY | BattleVerse L1 | BitWin
1
Ajeeb aadmi hai, isko padhna nahi aata kya?
Jay Bansal
43
TBH... we can point fingers both ways, right? Not all but may times it can get very emotional and targeting. I have talked with Mike, and I understand where he is coming from ...
Carl Parker
12
I swear @MikeHerron looks at my calendar and jumps in when I am in meetings! LOL Anyways... we get some venting out of our systems today? Will restate again... we both have ...
Carl Parker
5
Mike Calling people here "stupid" and "sell your kda" what kind of manager is this??? If I'm his boss, he gets a letter of dismissal now, anyway after the speech of your "mark...
Spanz y
13
A couple of other tidbits just because I'm feeling saucy today. 1. If you already know about KDA and/or Kadena (which are different) why would I put paid support behind try...
Mike Herron
2
а зачем этот вопрос для удаления из чата?
Mёdkinson Medvezhkin
63
Only that screenshot was leaked. The question is how much information of this type has been released in that group?
Palmar 🎧 | Sound Element
12
It's the same people who keep importing their narrative into BCH spaces again and again. @BitcoinCashPodcast , @chrisgoodwin79 People that want to read toxic maxi spam can a...
2qx#72497; 🦇
9
My feelings on this: To @appmandolin point. You have to ask yourself, why was this channel made in the first place? The name "EOS Elites" itself insinuates there's a class o...
Kameron James | zeos.one
3
Карта сайта