The reason is that there is no call
session.rollback()
Solution:
@contextmanager
def session_scope(self):
self.db_engine = create_engine(self.db_config, pool_pre_ping=True) # echo=True if needed to see background SQL
Session = sessionmaker(bind=self.db_engine)
session = Session()
try:
# this is where the "work" happens!
yield session
# always commit changes!
session.commit()
except:
# if any kind of exception occurs, rollback transaction
session.rollback()
raise
finally:
session.close()
Another form:
try:
......
......
......
......
except Exception:
import traceback
traceback.print_exc()
db.session.rollback()
pass
finally:
db.session.close()
pass
Read More:
- [Solved] error in REfO setup command: use_2to3 is invalid.
- [Solved] error in pycallgraph setup command: use_2to3 is invalid.
- [Solved] Jupyter Notebook Error: SparkException: Python worker failed to connect back
- Mxnet Export onnx Symbol and params files provided are invalid
- [Solved] RuntimeError (note: full exception trace is shown but execution is paused at: <module>)
- [Solved] rdd.foreach(print) Error: SyntaxError: invalid syntax
- Django CSV file Error: UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xb5 in position 0: invalid start
- [ONNXRuntimeError] : 10 : INVALID_Graph loading model error
- [Solved] yolo Error: IndexError: invalid index to scalar variable.
- [Solved] PyTorch Caught RuntimeError in DataLoader worker process 0和invalid argument 0: Sizes of tensors mus
- [Solved] pycuda._driver.LogicError: cuFuncSetBlockShape failed: invalid resource handle
- RuntimeError: Invalid DISPLAY variable [How to Solve]
- Python syntax error except exception, e: ^ syntax error: invalid syntax
- [Solved] UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xbf in position 7: invalid start byte
- Python Pandas Typeerror: invalid type comparison
- How to Solve Python WARNING: Ignoring invalid distribution -ip (e:\python\python_dowmload\lib\site-packages)
- [Solved] Failed to install PIP for MacOS, prompt: syntax error: invalid syntax
- [Solved] Python operate Kafka error: SyntaxError: invalid syntax
- [Solved] HttpRunner Error: Invalid testcase path or testcases: startproject
- [Solved] YOLOv5 Model training error: TypeError: new(): invalid data type ‘str’