Skip to content

Conversation

@WasimTTY
Copy link

@WasimTTY WasimTTY commented Jan 23, 2025

This pull request addresses compatibility issues with the original code, introduces logging based on the -d flag for debug mode, ensures the application’s dependencies are locked using Astra UV for more stable and reproducible deployments, and fixes an issue where reloading the page caused the form to be resubmitted, leading to duplicate files. Uses gunicorn as WSGI server instead of bjoern which required os-level dependencies to be installed as a prerequisite.

Key changes:

1. Flask version compatibility

The original code used safe_join from Flask, which is not available in Flask 3.x. The safe_join function has been moved to werkzeug.utils starting from Flask 2.2.x and onwards.

2. Logging setup

  • Logging has been added to the application. Logs are written to both the console and a file (blck.log) only when the -d flag is provided, indicating debug mode.
  • In production (when run with Gunicorn), logging will be handled by gunicorn.

3. Fix for Duplicate File Upload on Page Reload

After a successful upload, a file URL gets displayed and when the reload button on the browser is clicked, it triggers a form submission which results in the same file getting submitted multiple times resulting in duplicate (same file different URLs).

Screencastfrom23-01-25050348PMIST-ezgif com-video-to-gif-converter

The below image is a fix for preventing the resubmission of form.

Screencastfrom23-01-25040954PMIST-ezgif com-video-to-gif-converter

Clicking refresh on the browser no longer triggers the resubmission of the form.

Testing

1. Local testing:

  • The application was tested locally with both the -d flag and without it, ensuring that logs are written correctly based on the mode.
  • The below image is with debug mode.

image

  • This one with the logs written to a file.

image

  • The below image is with the debug mode turned off(Flask's server).

image

2. Production testing:

  • When deployed using gunicorn, the WSGI server handles the logging and the logs will be written to file.

  • The access logs will be written to access.log file and the error logs will be written to error.log file.

  • The below image represents the access.log

image

  • The one below represents the error.log/log file

image

4. Astra UV dependency locking:

  • Tested by locking dependencies, this mitigates issues that arise from differences in package versions when deploying and running the application.

WasimTTY and others added 22 commits November 24, 2024 20:12
* Updated blck.py to flask 3.x

* Updated blck.py with logging

* Create Dockerfile

* Create requirements.txt

* Update Dockerfile

* Update Dockerfile

* build: modify Dockerfile

* build:modify Dockerfile

* Delete requirements.txt

* build: updated Dockerfile

* Create requirements.in

* Rename requirements.in to requirements.txt

* Update Dockerfile

* Update Dockerfile

* Update and rename requirements.txt to requirements.in

* Create requirements.txt

* Create install_OS-dependencies.sh

* modify install_OS-dependencies.sh

* Update install_OS-dependencies.sh

* added pyproject.toml & uv.lock files via uv init

* build:modify Dockerfile

* Update pyproject.toml

* Delete install_OS-dependencies.sh

* modify:build Dockerfile

* modify:pyproject.toml

* generated requirements.txt

* modify:uv.lock

* created .dockerignore

* Delete requirements.in

* modify: build Dockerfile

* Update Dockerfile

---------

Co-authored-by: root <root@ip-172-31-93-252.ec2.internal>
Co-authored-by: root <root@ip-172-31-26-242.ec2.internal>
This reverts commit 45294bc.
@WasimTTY WasimTTY changed the title Fix Flask 3.x compatibility, Debug Logging, Astra UV locking, and prevent duplicate File uploads on reload Fix flask 3.x compatibility, Debug logging, Astra UV locking, and prevent duplicate File uploads on reload Jan 24, 2025
@WasimTTY WasimTTY marked this pull request as ready for review January 24, 2025 05:41
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.

1 participant