Error With Postgres Database if i add commit and roleback methout without Chain then it works

postgresql:
  image: postgres:11.8
  environment:
     POSTGRES_PASSWORD: 123
   volumes:
     - postgresql-data:/var/lib/postgresql/data

Hi I am using Postgres Database and above is the docker-compose.yml file data for postgres and when i want to create site getting error

tch.1    | Watching for changes...
06:42:35 web.1      | Syntax error in query:
06:42:35 web.1      | rollback and chain 
06:42:35 web.1      | 172.18.0.1 - - [14/Sep/2025 06:42:35] "GET /app/home HTTP/1.1" 500 -
06:42:35 web.1      | Traceback (most recent call last):
06:42:35 web.1      |   File "/workspace/development/mgrant/apps/frappe/frappe/middlewares.py", line 16, in __call__
06:42:35 web.1      |     return super().__call__(environ, start_response)
06:42:35 web.1      |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
06:42:35 web.1      |   File "/workspace/development/mgrant/env/lib/python3.11/site-packages/werkzeug/middleware/shared_data.py", line 250, in __call__
06:42:35 web.1      |     return self.app(environ, start_response)
06:42:35 web.1      |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
06:42:35 web.1      |   File "/workspace/development/mgrant/env/lib/python3.11/site-packages/werkzeug/middleware/shared_data.py", line 250, in __call__
06:42:35 web.1      |     return self.app(environ, start_response)
06:42:35 web.1      |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
06:42:35 web.1      |   File "/workspace/development/mgrant/apps/frappe/frappe/app.py", line 84, in application
06:42:35 web.1      |     app(environ, start_response),
06:42:35 web.1      |   File "/workspace/development/mgrant/env/lib/python3.11/site-packages/werkzeug/wrappers/request.py", line 193, in application
06:42:35 web.1      |     resp = f(*args[:-2] + (request,))
06:42:35 web.1      |            ^^^^^^^^^^^^^^^^^^^^^^^^^^
06:42:35 web.1      |   File "/workspace/development/mgrant/apps/frappe/frappe/app.py", line 144, in application
06:42:35 web.1      |     sync_database()
06:42:35 web.1      |   File "/workspace/development/mgrant/apps/frappe/frappe/app.py", line 423, in sync_database
06:42:35 web.1      |     db.rollback(chain=True)
06:42:35 web.1      |   File "/workspace/development/mgrant/apps/frappe/frappe/database/database.py", line 1208, in rollback
06:42:35 web.1      |     self.sql("rollback and chain")
06:42:35 web.1      |   File "/workspace/development/mgrant/apps/frappe/frappe/database/postgres/database.py", line 234, in sql
06:42:35 web.1      |     return super().sql(modify_query(query), modify_values(values), *args, **kwargs)
06:42:35 web.1      |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
06:42:35 web.1      |   File "/workspace/development/mgrant/apps/frappe/frappe/database/database.py", line 271, in sql
06:42:35 web.1      |     self.execute_query(query, values)
06:42:35 web.1      |   File "/workspace/development/mgrant/apps/frappe/frappe/database/database.py", line 365, in execute_query
06:42:35 web.1      |     return self._cursor.execute(query, values)
06:42:35 web.1      |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
06:42:35 web.1      | psycopg2.errors.SyntaxError: syntax error at or near "and"
06:42:35 web.1      | LINE 1: rollback and chain
06:42:35 web.1      |                  ^
06:42:35 web.1      | 
06:42:35 web.1      | 172.18.0.1 - - [14/Sep/2025 06:42:35] "GET /app/home?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1" 200 -
06:42:35 web.1      | 172.18.0.1 - - [14/Sep/2025 06:42:35] "GET /app/home?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1" 200 -
06:42:35 web.1      | 172.18.0.1 - - [14/Sep/2025 06:42:35] "GET /app/home?__debugger__=yes&cmd=resource&f=console.png&s=1tEaSVFT3t1q9oCwZ2kY HTTP/1.1" 200 -
06:42:35 web.1      | 172.18.0.1 - - [14/Sep/2025 06:42:35] "GET /app/home?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 200 -
06:49:29 web.1      |  * To enable the debugger you need to enter the security pin:
06:49:29 web.1      |  * Debugger pin code: 427-606-163
06:49:29 web.1      | 172.18.0.1 - - [14/Sep/2025 06:49:29] "GET /app/home?__debugger__=yes&cmd=printpin&s=1tEaSVFT3t1q9oCwZ2kY HTTP/1.1" 200 -
06:49:35 web.1      | 172.18.0.1 - - [14/Sep/2025 06:49:35] "GET /app/home?__debugger__=yes&cmd=pinauth&pin=123&s=1tEaSVFT3t1q9oCwZ2kY HTTP/1.1" 200 -
06:49:37 web.1      | 172.18.0.1 - - [14/Sep/2025 06:49:37] "GET /app/home?__debugger__=yes&cmd=pinauth&pin=123&s=1tEaSVFT3t1q9oCwZ2kY HTTP/1.1" 200 -
06:49:48 web.1      | Syntax error in query:
06:49:48 web.1      | rollback and chain 
06:49:48 web.1      | 172.18.0.1 - - [14/Sep/2025 06:49:48] "GET /app/home HTTP/1.1" 500 -
06:49:48 web.1      | Traceback (most recent call last):
06:49:48 web.1      |   File "/workspace/development/mgrant/apps/frappe/frappe/middlewares.py", line 16, in __call__
06:49:48 web.1      |     return super().__call__(environ, start_response)
06:49:48 web.1      |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
06:49:48 web.1      |   File "/workspace/development/mgrant/env/lib/python3.11/site-packages/werkzeug/middleware/shared_data.py", line 250, in __call__
06:49:48 web.1      |     return self.app(environ, start_response)
06:49:48 web.1      |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
06:49:48 web.1      |   File "/workspace/development/mgrant/env/lib/python3.11/site-packages/werkzeug/middleware/shared_data.py", line 250, in __call__
06:49:48 web.1      |     return self.app(environ, start_response)
06:49:48 web.1      |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
06:49:48 web.1      |   File "/workspace/development/mgrant/apps/frappe/frappe/app.py", line 84, in application
06:49:48 web.1      |     app(environ, start_response),
06:49:48 web.1      |   File "/workspace/development/mgrant/env/lib/python3.11/site-packages/werkzeug/wrappers/request.py", line 193, in application
06:49:48 web.1      |     resp = f(*args[:-2] + (request,))
06:49:48 web.1      |            ^^^^^^^^^^^^^^^^^^^^^^^^^^
06:49:48 web.1      |   File "/workspace/development/mgrant/apps/frappe/frappe/app.py", line 144, in application
06:49:48 web.1      |     sync_database()
06:49:48 web.1      |   File "/workspace/development/mgrant/apps/frappe/frappe/app.py", line 423, in sync_database
06:49:48 web.1      |     db.rollback(chain=True)
06:49:48 web.1      |   File "/workspace/development/mgrant/apps/frappe/frappe/database/database.py", line 1208, in rollback
06:49:48 web.1      |     self.sql("rollback and chain")
06:49:48 web.1      |   File "/workspace/development/mgrant/apps/frappe/frappe/database/postgres/database.py", line 234, in sql
06:49:48 web.1      |     return super().sql(modify_query(query), modify_values(values), *args, **kwargs)
06:49:48 web.1      |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
06:49:48 web.1      |   File "/workspace/development/mgrant/apps/frappe/frappe/database/database.py", line 271, in sql
06:49:48 web.1      |     self.execute_query(query, values)
06:49:48 web.1      |   File "/workspace/development/mgrant/apps/frappe/frappe/database/database.py", line 365, in execute_query
06:49:48 web.1      |     return self._cursor.execute(query, values)
06:49:48 web.1      |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
06:49:48 web.1      | psycopg2.errors.SyntaxError: syntax error at or near "and"
06:49:48 web.1      | LINE 1: rollback and chain
06:49:48 web.1      |                  ^

if I am adding a commit and roleback methods in database.py of postgress db class

	def commit(self, *, chain=False):
		"""Commit current transaction. Only use COMMIT for PostgreSQL."""
		if getattr(self, "_disable_transaction_control", False):
			import warnings

			warnings.warn(message="Transaction control is disabled.", stacklevel=2)
			return

		self.before_rollback.reset()
		self.after_rollback.reset()
		self.before_commit.run()

		self.sql("COMMIT")
		self.begin()

		self.after_commit.run()

	def rollback(self, *, save_point=None, chain=False):
		"""Rollback current transaction. Optionally rollback to a known save_point."""
		if save_point:
			self.sql(f"ROLLBACK TO SAVEPOINT {save_point}")
		elif not getattr(self, "_disable_transaction_control", False):
			self.before_commit.reset()
			self.after_commit.reset()
			self.before_rollback.run()

			self.sql("ROLLBACK")
			self.begin()

			self.after_rollback.run()
		else:
			import warnings

			warnings.warn(message=TRANSACTION_DISABLED_MSG, stacklevel=2)

postgresql:
  image: postgres:14
  environment:
     POSTGRES_PASSWORD: 123
   volumes:
     - postgresql-data:/var/lib/postgresql/data

if i upgrade to version 14 then this problem is fixed.

1 Like