Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
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
ai-tech
dify
Commits
2381264a
Unverified
Commit
2381264a
authored
Jan 03, 2024
by
takatost
Committed by
GitHub
Jan 03, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: provider create cause IntegrityError (#1866)
parent
4562e83b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
11 deletions
+24
-11
provider_manager.py
api/core/provider_manager.py
+24
-11
No files found.
api/core/provider_manager.py
View file @
2381264a
...
@@ -3,6 +3,8 @@ from collections import defaultdict
...
@@ -3,6 +3,8 @@ from collections import defaultdict
from
json
import
JSONDecodeError
from
json
import
JSONDecodeError
from
typing
import
Optional
from
typing
import
Optional
from
psycopg2
import
IntegrityError
from
core.entities.model_entities
import
DefaultModelEntity
,
DefaultModelProviderEntity
from
core.entities.model_entities
import
DefaultModelEntity
,
DefaultModelProviderEntity
from
core.entities.provider_configuration
import
ProviderConfigurations
,
ProviderConfiguration
,
ProviderModelBundle
from
core.entities.provider_configuration
import
ProviderConfigurations
,
ProviderConfiguration
,
ProviderModelBundle
from
core.entities.provider_entities
import
CustomConfiguration
,
CustomProviderConfiguration
,
CustomModelConfiguration
,
\
from
core.entities.provider_entities
import
CustomConfiguration
,
CustomProviderConfiguration
,
CustomModelConfiguration
,
\
...
@@ -380,17 +382,28 @@ class ProviderManager:
...
@@ -380,17 +382,28 @@ class ProviderManager:
if
quota
.
quota_type
==
ProviderQuotaType
.
TRIAL
:
if
quota
.
quota_type
==
ProviderQuotaType
.
TRIAL
:
# Init trial provider records if not exists
# Init trial provider records if not exists
if
ProviderQuotaType
.
TRIAL
not
in
provider_quota_to_provider_record_dict
:
if
ProviderQuotaType
.
TRIAL
not
in
provider_quota_to_provider_record_dict
:
provider_record
=
Provider
(
try
:
tenant_id
=
tenant_id
,
provider_record
=
Provider
(
provider_name
=
provider_name
,
tenant_id
=
tenant_id
,
provider_type
=
ProviderType
.
SYSTEM
.
value
,
provider_name
=
provider_name
,
quota_type
=
ProviderQuotaType
.
TRIAL
.
value
,
provider_type
=
ProviderType
.
SYSTEM
.
value
,
quota_limit
=
quota
.
quota_limit
,
quota_type
=
ProviderQuotaType
.
TRIAL
.
value
,
quota_used
=
0
,
quota_limit
=
quota
.
quota_limit
,
is_valid
=
True
quota_used
=
0
,
)
is_valid
=
True
db
.
session
.
add
(
provider_record
)
)
db
.
session
.
commit
()
db
.
session
.
add
(
provider_record
)
db
.
session
.
commit
()
except
IntegrityError
:
db
.
session
.
rollback
()
provider_record
=
db
.
session
.
query
(
Provider
)
\
.
filter
(
Provider
.
tenant_id
==
tenant_id
,
Provider
.
provider_name
==
provider_name
,
Provider
.
provider_type
==
ProviderType
.
SYSTEM
.
value
,
Provider
.
quota_type
==
ProviderQuotaType
.
TRIAL
.
value
,
Provider
.
is_valid
==
True
)
.
first
()
provider_name_to_provider_records_dict
[
provider_name
]
.
append
(
provider_record
)
provider_name_to_provider_records_dict
[
provider_name
]
.
append
(
provider_record
)
...
...
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