Skip to content

Fix: Ensure st.set_page_config is first Streamlit call in Home page#97

Merged
Devasy merged 4 commits intoDevasy:mainfrom
Samudra-G:fix/frontend-home
Jul 30, 2025
Merged

Fix: Ensure st.set_page_config is first Streamlit call in Home page#97
Devasy merged 4 commits intoDevasy:mainfrom
Samudra-G:fix/frontend-home

Conversation

@Samudra-G
Copy link
Contributor

@Samudra-G Samudra-G commented Jul 30, 2025

💠 Fix: Ensure st.set_page_config is the first Streamlit command in Home page

📄 Description

This PR fixes a critical bug in the Home.py page where st.set_page_config() was being called after some other Streamlit-related imports or calls — which violates Streamlit’s requirement that this method must be the first Streamlit command executed.

The error resolved was:

StreamlitSetPageConfigMustBeFirstCommandError:
set_page_config() can only be called once per app page, and must be called as the first Streamlit command in your script.

✅ Changes Made

  • Moved st.set_page_config(...) to appear immediately after import streamlit as st, before all other imports or Streamlit-related code.
  • Converted top-level docstring to a comment to avoid unintended execution order issues.

🔍 Affected File

  • Home.py

📌 Why this is necessary

Streamlit enforces set_page_config() to be the very first Streamlit command — even before any imports that may use st.*. This was silently violated due to indirect Streamlit usage in early imports.


🔪 Testing

  • Verified that the app now loads without the StreamlitSetPageConfigMustBeFirstCommandError.
  • Other functionalities in Home.py remain intact.

⚠️ Caution

Note: The behavior of st.cache was updated in Streamlit 1.36 to the new caching
logic used by st.cache_data and st.cache_resource. This might lead to some problems
or unexpected behavior in certain edge cases.

Summary by CodeRabbit

  • Documentation

    • Added a comment clarifying the required order of Streamlit commands for proper page configuration.
  • Style

    • Reordered import statements for improved readability and consistency.

@Samudra-G Samudra-G requested a review from Devasy as a code owner July 30, 2025 16:23
@netlify
Copy link

netlify bot commented Jul 30, 2025

Deploy Preview for splitwizer failed. Why did it fail? →

Name Link
🔨 Latest commit 5f13e8e
🔍 Latest deploy log https://app.netlify.com/projects/splitwizer/deploys/688a4f01909de900088f5ea2

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 30, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The import statements in ui-poc/Home.py were reordered to place EncryptedCookieManager immediately after streamlit. The st.set_page_config() call was moved to directly follow the streamlit import, accompanied by a new comment emphasizing that it must be the first Streamlit command. No functional or logical changes were made.

Changes

Cohort / File(s) Change Summary
Import and Streamlit Setup Reordering
ui-poc/Home.py
Reordered imports to place EncryptedCookieManager after streamlit; moved st.set_page_config() up and added a comment enforcing its placement as the first Streamlit command.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐇
I hopped through lines, imports in tow,
Placed them just so, in a tidy row.
With comments to guide where Streamlit must start,
Organization and clarity—an art!
Now the code is neat, so onward we go!

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4647c43 and 5f13e8e.

📒 Files selected for processing (1)
  • ui-poc/Home.py (2 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
ui-poc/Home.py (1)

3-4: Remove unused datetime and json imports

Static analysis (ruff F401) flags both as unused. Eliminating dead imports reduces startup time and lint noise.

-from datetime import datetime
-import json
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ca38e84 and 4647c43.

📒 Files selected for processing (1)
  • ui-poc/Home.py (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
ui-poc/Home.py

📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)

ui-poc/Home.py: Frontend POC must be implemented using Streamlit, with the entry point in ui-poc/Home.py.
Streamlit session state must be used to manage user sessions in the frontend, as shown in Home.py.

Files:

  • ui-poc/Home.py
🧠 Learnings (2)
📓 Common learnings
Learnt from: CR
PR: Devasy23/splitwiser#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-26T09:41:01.332Z
Learning: Applies to ui-poc/Home.py : Frontend POC must be implemented using Streamlit, with the entry point in ui-poc/Home.py.
Learnt from: CR
PR: Devasy23/splitwiser#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-26T09:41:01.332Z
Learning: Applies to ui-poc/Home.py : Streamlit session state must be used to manage user sessions in the frontend, as shown in Home.py.
Learnt from: CR
PR: Devasy23/splitwiser#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-26T09:41:01.332Z
Learning: Applies to ui-poc/pages/*.py : Frontend POC application pages must be placed in ui-poc/pages/ as individual Python files.
Learnt from: CR
PR: Devasy23/splitwiser#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-26T09:41:01.332Z
Learning: Applies to ui-poc/pages/*.py : When adding a new UI component, modify or add files in /ui-poc/pages/.
ui-poc/Home.py (2)

Learnt from: CR
PR: Devasy23/splitwiser#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-26T09:41:01.332Z
Learning: Applies to ui-poc/Home.py : Frontend POC must be implemented using Streamlit, with the entry point in ui-poc/Home.py.

Learnt from: CR
PR: Devasy23/splitwiser#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-26T09:41:01.332Z
Learning: Applies to ui-poc/Home.py : Streamlit session state must be used to manage user sessions in the frontend, as shown in Home.py.

🪛 Ruff (0.12.2)
ui-poc/Home.py

3-3: datetime.datetime imported but unused

Remove unused import: datetime.datetime

(F401)


4-4: json imported but unused

Remove unused import: json

(F401)

🔇 Additional comments (1)
ui-poc/Home.py (1)

14-18: 👍 Clear explanatory comment added

The note succinctly documents the Streamlit ordering rule and will help future contributors avoid the same pitfall.

Devasy and others added 2 commits July 30, 2025 22:27
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@Devasy Devasy added bug Something isn't working good first issue Good for newcomers gssoc25 level1 labels Jul 30, 2025
@github-project-automation github-project-automation bot moved this to Backlog in Splitwiser Jul 30, 2025
@Devasy Devasy moved this from Backlog to In review in Splitwiser Jul 30, 2025
@Devasy Devasy merged commit 9912b69 into Devasy:main Jul 30, 2025
34 of 40 checks passed
@github-project-automation github-project-automation bot moved this from In review to Done in Splitwiser Jul 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working good first issue Good for newcomers gssoc25 level1

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants