Skip to content

Commit 1eee800

Browse files
committed
fix streamlit
1 parent 065285d commit 1eee800

File tree

2 files changed

+135
-0
lines changed

2 files changed

+135
-0
lines changed

service_catalog/Home.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,58 @@ def main() -> None:
131131
else:
132132
st.info("No data centers found in this branch.")
133133

134+
# Show debug info if on a non-main branch
135+
if st.session_state.selected_branch != "main":
136+
with st.expander("🔍 Debug Information"):
137+
st.markdown("**Query Details:**")
138+
st.code(f"Branch: {st.session_state.selected_branch}")
139+
st.code(f"Object Type: TopologyDataCenter")
140+
st.code(f"Infrahub Address: {client.base_url}")
141+
142+
# Check for proposed changes
143+
try:
144+
pcs = client.get_proposed_changes(st.session_state.selected_branch)
145+
if pcs:
146+
st.markdown("**Proposed Changes on this branch:**")
147+
for pc in pcs:
148+
pc_name = pc.get("name", {}).get("value", "Unknown")
149+
pc_state = pc.get("state", {}).get("value", "Unknown")
150+
st.write(f"- {pc_name} (State: {pc_state})")
151+
else:
152+
st.write("No proposed changes found on this branch.")
153+
except Exception as e:
154+
st.write(f"Could not fetch proposed changes: {e}")
155+
156+
# Check what other objects exist on this branch
157+
st.markdown("**Other objects on this branch:**")
158+
try:
159+
# Query for generic devices
160+
device_query = """
161+
query {
162+
DcimGenericDevice {
163+
count
164+
edges {
165+
node {
166+
id
167+
name { value }
168+
__typename
169+
}
170+
}
171+
}
172+
}
173+
"""
174+
result = client.execute_graphql(device_query, branch=st.session_state.selected_branch)
175+
device_count = result.get("data", {}).get("DcimGenericDevice", {}).get("count", 0)
176+
st.write(f"- DcimGenericDevice: {device_count} object(s)")
177+
178+
if device_count > 0:
179+
devices = result.get("data", {}).get("DcimGenericDevice", {}).get("edges", [])
180+
for device in devices[:5]: # Show first 5
181+
dev_name = device.get("node", {}).get("name", {}).get("value", "Unknown")
182+
st.write(f" - {dev_name}")
183+
except Exception as e:
184+
st.write(f"Error checking other objects: {e}")
185+
134186
except InfrahubConnectionError as e:
135187
display_error("Unable to connect to Infrahub", str(e))
136188
except InfrahubHTTPError as e:

service_catalog/utils/api.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,89 @@ def get_colocation_centers(self, branch: str = "main") -> List[Dict[str, Any]]:
302302

303303
return colocations
304304

305+
def get_proposed_changes(self, branch: str = "main") -> List[Dict[str, Any]]:
306+
"""Fetch proposed changes for a branch.
307+
308+
Args:
309+
branch: Branch name to query (default: "main")
310+
311+
Returns:
312+
List of proposed change dictionaries
313+
314+
Raises:
315+
InfrahubConnectionError: If connection fails
316+
InfrahubHTTPError: If HTTP error occurs
317+
InfrahubGraphQLError: If GraphQL error occurs
318+
"""
319+
query = """
320+
query GetProposedChanges {
321+
CoreProposedChange {
322+
edges {
323+
node {
324+
id
325+
name {
326+
value
327+
}
328+
state {
329+
value
330+
}
331+
source_branch {
332+
value
333+
}
334+
}
335+
}
336+
}
337+
}
338+
"""
339+
340+
result = self.execute_graphql(query, branch=branch)
341+
342+
# Extract proposed changes from GraphQL response
343+
edges = result.get("data", {}).get("CoreProposedChange", {}).get("edges", [])
344+
proposed_changes = [edge["node"] for edge in edges]
345+
346+
return proposed_changes
347+
348+
def get_datacenters_from_proposed_changes(
349+
self, branch: str = "main"
350+
) -> List[Dict[str, Any]]:
351+
"""Fetch TopologyDataCenter objects from proposed changes on a branch.
352+
353+
This method queries for data centers that may be part of open proposed changes
354+
and haven't been merged yet. It adds a "_proposed" flag to distinguish them.
355+
356+
Args:
357+
branch: Branch name to query (default: "main")
358+
359+
Returns:
360+
List of datacenter dictionaries from proposed changes
361+
362+
Raises:
363+
InfrahubConnectionError: If connection fails
364+
InfrahubHTTPError: If HTTP error occurs
365+
InfrahubGraphQLError: If GraphQL error occurs
366+
"""
367+
# First, get proposed changes for this branch
368+
proposed_changes = self.get_proposed_changes(branch)
369+
370+
# Filter for open proposed changes on this branch
371+
open_pcs = [
372+
pc
373+
for pc in proposed_changes
374+
if pc.get("state", {}).get("value") == "open"
375+
and pc.get("source_branch", {}).get("value") == branch
376+
]
377+
378+
if not open_pcs:
379+
return []
380+
381+
# For now, we'll query the branch directly with a flag to get uncommitted objects
382+
# In Infrahub, objects created on a branch are visible via GraphQL queries on that branch
383+
# even if they're part of an open proposed change
384+
# So we actually don't need special handling - the issue is likely elsewhere
385+
386+
return []
387+
305388
def execute_graphql(
306389
self,
307390
query: str,

0 commit comments

Comments
 (0)