Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore query parameters in request #6327

Merged
merged 7 commits into from
Nov 7, 2023
Merged

Restore query parameters in request #6327

merged 7 commits into from
Nov 7, 2023

Conversation

aliabid94
Copy link
Collaborator

@aliabid94 aliabid94 commented Nov 7, 2023

We lost query parameters in the request in upgrading to 4.0, because we were sending the queue information (session_hash, fn_index) via query params - now we send both URL params and queue information via request.url_params.
This does mean that when a user searches the request for url_params, there will be additional url_parameters they will find now in 4.0. I wanted to strip these but the fastapi.Request object is immutable and would be very messy / hacky to create a new object without these URL parameters. I think this is okay because users are usually looking for a specific key when searching url parameters.

Fixes: #6283

Try with

import gradio as gr

def echo(params):
    print(params)
    return params

def get_params(request: gr.Request):
  params = request.query_params
  ip = request.client.host
  return {"params": params, 
          "ip": ip}

  
with gr.Blocks() as demo:
  url_params = gr.State()
  text_in = gr.Textbox()
  text_out = gr.JSON()
  btn = gr.Button()
  btn.click(echo, inputs=[url_params], outputs=[text_out])
  demo.load(get_params, None, url_params, queue=True)
  #demo.load(get_params, None, url_params, queue=False)

demo.launch()

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Nov 7, 2023

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
🦄 Changes detected! Details
📓 Notebooks not matching! Details

The demo notebooks don't match the run.py files. Please run this command from the root of the repo and then commit the changes:

pip install nbformat && cd demo && python generate_notebooks.py

Install Gradio from this PR

pip install https://gradio-builds.s3.amazonaws.com/b5dcbe6c78839336a1041520e3a0f7d83a2aefe5/gradio-4.1.1-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@b5dcbe6c78839336a1041520e3a0f7d83a2aefe5#subdirectory=client/python"

@aliabid94 aliabid94 requested review from abidlabs and pngwn November 7, 2023 19:53
@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Nov 7, 2023

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
@gradio/client patch
gradio patch
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Restore query parameters in request

Maintainers or the PR author can modify the PR title to modify this entry.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

@abidlabs
Copy link
Member

abidlabs commented Nov 7, 2023

LGTM @aliabid94

@aliabid94 aliabid94 merged commit bca6c2c into main Nov 7, 2023
@aliabid94 aliabid94 deleted the restore_query_params branch November 7, 2023 23:15
@pngwn pngwn mentioned this pull request Nov 7, 2023
@liquidcarbon
Copy link

this is currently not working:
TypeError: Type is not JSON serializable: QueryParams

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

URL query parameters with queue is broken
4 participants