# system.db.runPrepUpdate can't use database name in decorator?

**URL:** <https://forum.inductiveautomation.com/t/system-db-runprepupdate-cant-use-database-name-in-decorator/112873>\
**Category:** Ignition\
**Tags:** scripting, ignition83\
**Created:** [December 17, 2025, 7:25pm UTC](https://forum.inductiveautomation.com/t/system-db-runprepupdate-cant-use-database-name-in-decorator/112873 "2025-12-17T19:25:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Lindon](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@Michael\_Lindon](https://forum.inductiveautomation.com/u/Michael_Lindon)\
**Post date:** [December 17, 2025, 7:25pm UTC](https://forum.inductiveautomation.com/t/system-db-runprepupdate-cant-use-database-name-in-decorator/112873/1 "2025-12-17T19:25:00Z")

</div>

I was recently tasked with switching our database structure and was looking forward to using my new architecture to change the values in a few locations to get everything working, however I ran into a snag. To ensure all queries run safely and rollback with consistent logic, I put together the below Safe Txn Decorator. However, if system.db.runPrepUpdate is run in the decorated function (func) it ignores the database field and goes straight to using the project default. I removed the Decorator from the source function and it worked without issue.

```python
def _Dec_SafeTxn():
	def decorator(func):
		@wraps(func)
		def wrapper(self, *args, **kwargs):
			if not "txId" in kwargs or not kwargs["txId"]:
				txn = system.db.beginTransaction(self.database.name)
				isTxId = False
			else:
				txn = kwargs["txId"]
				isTxId = True
			
			del kwargs["txId"]
				
			try:
				out = func(self, *args, txId = txn, **kwargs)
				
				if isTxId:
					if self.testMode:
						system.db.rollbackTransaction(txn)
					else:
						system.db.commitTransaction(txn)
				
			except java.lang.Exception as e:
				if not isTxId:
					system.db.rollbackTransaction(txn)
				
				if e.getCause():
					message = e.getCause().getMessage()
				else:
					message = str(e)
					
				Logger(loggerName = 'Safe Txn Logger').error(message)
				raise
			except Exception as e:
				if not isTxId:
					system.db.rollbackTransaction(txn)
				
				LoggerException(loggerName = 'Safe Txn Logger').error(e)
				raise
			finally:
				if not isTxId:
					system.db.closeTransaction(txn)
					
			return out
	
		return wrapper
	return decorator

```

This was inconvenient during testing and I can get by with changing the project Database, but want to know if this is a bug or I am doing something wrong?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 17, 2025, 7:36pm UTC](https://forum.inductiveautomation.com/t/system-db-runprepupdate-cant-use-database-name-in-decorator/112873/2 "2025-12-17T19:36:18Z")

</div>

To confirm, your issue is that something like this:

```python

@_Dec_SafeTxn
def doSomethingWithTheDb():
    system.db.runPrepUpdate(...)

```

Doesn't use the transaction in the inner call to `runPrepUpdate`?

---

<div class="post-metadata">

**Author:** ![Michael\_Lindon](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@Michael\_Lindon](https://forum.inductiveautomation.com/u/Michael_Lindon)\
**Post date:** [December 17, 2025, 8:28pm UTC](https://forum.inductiveautomation.com/t/system-db-runprepupdate-cant-use-database-name-in-decorator/112873/3 "2025-12-17T20:28:13Z")

</div>

> [@paul-griffith](#):
>
> ```python
> @_Dec_SafeTxn
> def doSomethingWithTheDb():
> system.db.runPrepUpdate(...)
> 
> ```

Yes, though @\_Dec\_SafeTxn() needs the parentheses. The issue is that system.db.runPrepUpdate(qry, args, database = “DatabaseConnection”) in this case isn’t using “DatabaseConnection”, it uses the project default database instead.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 17, 2025, 11:29pm UTC](https://forum.inductiveautomation.com/t/system-db-runprepupdate-cant-use-database-name-in-decorator/112873/4 "2025-12-17T23:29:49Z")

</div>

In gateway or client scope?

---

<div class="post-metadata">

**Author:** ![Michael\_Lindon](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@Michael\_Lindon](https://forum.inductiveautomation.com/u/Michael_Lindon)\
**Post date:** [December 17, 2025, 11:53pm UTC](https://forum.inductiveautomation.com/t/system-db-runprepupdate-cant-use-database-name-in-decorator/112873/5 "2025-12-17T23:53:07Z")

</div>

Same effect in both the script console and through a perspective event script. Didn’t check carefully, but I wasn’t getting writes from gateway timer events either.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 18, 2025, 12:09am UTC](https://forum.inductiveautomation.com/t/system-db-runprepupdate-cant-use-database-name-in-decorator/112873/6 "2025-12-18T00:09:01Z")

</div>

Thanks. I'll throw it on my list to investigate, but with the holidays coming up, not sure when that'll actually happen.

I'd also recommend making an official report to support to keep me honest and make sure you get informed if/when we do find a bug and get it fixed.
