Skip to content

Commit d056635

Browse files
committed
fix(connection): bug in changing sql flavor
1 parent 12852bd commit d056635

File tree

1 file changed

+16
-13
lines changed
  • testgen/ui/views/connections

1 file changed

+16
-13
lines changed

testgen/ui/views/connections/page.py

+16-13
Original file line numberDiff line numberDiff line change
@@ -76,26 +76,28 @@ def render(self, project_code: str, **_kwargs) -> None:
7676

7777
def show_connection_form(self, selected_connection: dict, _mode: str, project_code) -> None:
7878
connection = selected_connection or {}
79-
connection_id = connection.get("connection_id", None)
79+
connection_id = connection.get("connection_id", 1)
80+
connection_name = connection.get("connection_name", "default")
8081
sql_flavor = connection.get("sql_flavor", "postgresql")
8182
data = {}
8283

8384
try:
8485
FlavorForm = BaseConnectionForm.for_flavor(sql_flavor)
8586
if connection:
8687
connection["password"] = connection["password"] or ""
87-
FlavorForm = BaseConnectionForm.for_flavor(sql_flavor)
88-
89-
form_kwargs = connection or {"sql_flavor": sql_flavor}
88+
89+
form_kwargs = connection or {"sql_flavor": sql_flavor, "connection_id": connection_id, "connection_name": connection_name}
9090
form = FlavorForm(**form_kwargs)
9191

9292
sql_flavor = form.get_field_value("sql_flavor", latest=True) or sql_flavor
9393
if form.sql_flavor != sql_flavor:
94-
form = BaseConnectionForm.for_flavor(sql_flavor)(sql_flavor=sql_flavor)
94+
form = BaseConnectionForm.for_flavor(sql_flavor)(sql_flavor=sql_flavor, connection_id=connection_id)
95+
96+
form.disable("connection_name")
9597

9698
form_errors_container = st.empty()
9799
data = sp.pydantic_input(
98-
key=f"connection_form:{connection_id or 'new'}",
100+
key=f"connection_form:{connection_id}",
99101
model=form, # type: ignore
100102
)
101103
data.update({
@@ -120,16 +122,16 @@ def show_connection_form(self, selected_connection: dict, _mode: str, project_co
120122
st.error("Unexpected error displaying the form. Try again")
121123

122124
test_button_column, _, save_button_column = st.columns([.2, .6, .2])
123-
is_submitted, set_submitted = temp_value(f"connection_form-{connection_id or 'new'}:submit")
124-
get_connection_status, set_connection_status = temp_value(
125-
f"connection_form-{connection_id or 'new'}:test_conn"
125+
is_submitted, set_submitted = temp_value(f"connection_form-{connection_id}:submit")
126+
is_connecting, set_connecting = temp_value(
127+
f"connection_form-{connection_id}:test_conn"
126128
)
127129

128130
with save_button_column:
129131
testgen.button(
130132
type_="flat",
131133
label="Save",
132-
key=f"connection_form:{connection_id or 'new'}:submit",
134+
key=f"connection_form:{connection_id}:submit",
133135
on_click=lambda: set_submitted(True),
134136
)
135137

@@ -138,13 +140,14 @@ def show_connection_form(self, selected_connection: dict, _mode: str, project_co
138140
type_="stroked",
139141
color="basic",
140142
label="Test Connection",
141-
key=f"connection_form:{connection_id or 'new'}:test",
142-
on_click=lambda: set_connection_status(self.test_connection(data)),
143+
key=f"connection_form:{connection_id}:test",
144+
on_click=lambda: set_connecting(True),
143145
)
144146

145-
if (connection_status := get_connection_status()):
147+
if is_connecting():
146148
single_element_container = st.empty()
147149
single_element_container.info("Connecting ...")
150+
connection_status = self.test_connection(data)
148151

149152
with single_element_container.container():
150153
renderer = {

0 commit comments

Comments
 (0)