Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
A
aisbf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexlab
aisbf
Commits
6a14af79
Commit
6a14af79
authored
Apr 21, 2026
by
Stefy Lanza (nextime / spora )
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix: Properly handle NULL values in cache settings by checking existence before INSERT/UPDATE
parent
ec7c85aa
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
8 deletions
+26
-8
database.py
aisbf/database.py
+26
-8
No files found.
aisbf/database.py
View file @
6a14af79
...
...
@@ -2930,20 +2930,38 @@ class DatabaseManager:
placeholder
=
'?'
if
self
.
db_type
==
'sqlite'
else
'
%
s'
try
:
if
self
.
db_type
==
'sqlite'
:
# First, check if a record exists (handle NULL values explicitly)
if
provider_id
is
None
and
model_name
is
None
:
cursor
.
execute
(
f
'''
INSERT OR REPLACE INTO user_cache_settings
(user_id, provider_id, model_name, cache_enabled, updated_at)
VALUES ({placeholder}, {placeholder}, {placeholder}, {placeholder}, CURRENT_TIMESTAMP)
'''
,
(
user_id
,
provider_id
,
model_name
,
cache_enabled
))
SELECT id FROM user_cache_settings
WHERE user_id = {placeholder} AND provider_id IS NULL AND model_name IS NULL
'''
,
(
user_id
,))
elif
provider_id
is
not
None
and
model_name
is
None
:
cursor
.
execute
(
f
'''
SELECT id FROM user_cache_settings
WHERE user_id = {placeholder} AND provider_id = {placeholder} AND model_name IS NULL
'''
,
(
user_id
,
provider_id
))
else
:
cursor
.
execute
(
f
'''
SELECT id FROM user_cache_settings
WHERE user_id = {placeholder} AND provider_id = {placeholder} AND model_name = {placeholder}
'''
,
(
user_id
,
provider_id
,
model_name
))
existing
=
cursor
.
fetchone
()
if
existing
:
# Update existing record
cursor
.
execute
(
f
'''
UPDATE user_cache_settings
SET cache_enabled = {placeholder}, updated_at = CURRENT_TIMESTAMP
WHERE id = {placeholder}
'''
,
(
cache_enabled
,
existing
[
0
]))
else
:
# Insert new record
cursor
.
execute
(
f
'''
INSERT INTO user_cache_settings
(user_id, provider_id, model_name, cache_enabled, updated_at)
VALUES ({placeholder}, {placeholder}, {placeholder}, {placeholder}, CURRENT_TIMESTAMP)
ON DUPLICATE KEY UPDATE
cache_enabled = VALUES(cache_enabled),
updated_at = CURRENT_TIMESTAMP
'''
,
(
user_id
,
provider_id
,
model_name
,
cache_enabled
))
conn
.
commit
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment