5.3 KiB
Debugging URL Suffix Not Saving Issue
Problem
The app is not saving the URL suffix to the admin_settings table.
Debug Logging Added
I've added comprehensive debug logging to help diagnose the issue. The logs will show:
-
When the form is submitted:
- Which button was clicked (Save vs Activate)
- What form data was received
-
When saving settings:
- The generated URL suffix
- Whether the UPDATE query executed
- The result of the UPDATE query
- Verification of what's actually in the database
-
When activating voting:
- What URL suffix is retrieved from the database
- Whether a new suffix needs to be generated
- The final suffix being used
How to Debug
Step 1: Deploy the Updated Code
Deploy the updated code with debug logging to production:
# Build new image
docker build -t your-registry/motm-app:latest .
# Push to registry
docker push your-registry/motm-app:latest
# Deploy to Kubernetes
helm upgrade motm-app ./helm-chart/motm-app --namespace motm-app
Step 2: Test the MOTM Admin Page
- Go to https://motm.ervine.cloud/admin/motm
- Fill in the form:
- Match date
- Opposition team
- Current MOTM (optional)
- Current DotD (optional)
- Voting deadline (optional)
- Click "Save Settings" button
- Check the logs
Step 3: Check the Logs
# Get the pod name
kubectl get pods -n motm-app -l app.kubernetes.io/name=motm-app
# Watch the logs in real-time
kubectl logs -n motm-app -f <POD_NAME>
Or check recent logs:
kubectl logs -n motm-app -l app.kubernetes.io/name=motm-app --tail=100 | grep DEBUG
Step 4: Analyze the Debug Output
Look for these debug messages:
When clicking "Save Settings":
DEBUG: POST request received
DEBUG: form.saveButton.data = True
DEBUG: form.activateButton.data = False
DEBUG: Save button clicked
DEBUG: Form data - team: [team name], date: [date]
DEBUG: Generated URL suffix: [suffix]
DEBUG: About to execute UPDATE query
DEBUG: UPDATE query result: True
DEBUG: Verification - URL suffix in DB: [suffix]
When clicking "Activate MotM Vote":
DEBUG: POST request received
DEBUG: form.saveButton.data = False
DEBUG: form.activateButton.data = True
DEBUG: Activate button clicked
DEBUG: Form data - team: [team name], date: [date]
DEBUG: Getting URL suffix from database
DEBUG: Query result: [result]
DEBUG: Using existing suffix: [suffix]
DEBUG: Final suffix: [suffix]
Common Issues and Solutions
Issue 1: Button Click Not Detected
Symptoms:
DEBUG: POST request received
DEBUG: form.saveButton.data = False
DEBUG: form.activateButton.data = False
DEBUG: Something went wrong - check with Smithers
Cause: The form button data isn't being submitted correctly.
Solution: Check the HTML form to ensure the buttons have the correct name attribute.
Issue 2: UPDATE Query Fails
Symptoms:
DEBUG: UPDATE query result: False
Cause: The UPDATE query failed silently.
Solution: Check for SQL errors in the logs. The sql_write_static function prints errors.
Issue 3: UPDATE Succeeds but Value Not Saved
Symptoms:
DEBUG: UPDATE query result: True
DEBUG: Verification - URL suffix in DB: None
Cause: The UPDATE query executed but didn't actually update the row.
Solution:
- Check if the WHERE clause is matching a row
- Verify the table structure
- Check if there's a transaction rollback happening
Issue 4: Query Returns Empty Result
Symptoms:
DEBUG: Query result: []
Cause: No row matches the WHERE clause userid = 'admin'.
Solution:
- Check if the
useridcolumn has the value 'admin' - Run the diagnostic script:
check_production_db.py
Manual Verification
After clicking "Save Settings", verify the URL suffix was saved:
kubectl exec -it <POD_NAME> -n motm-app -- python -c "
from db_config import sql_read_static
from sqlalchemy import text
result = sql_read_static(text('SELECT motm_url_suffix FROM admin_settings WHERE userid = \\'admin\\''))
print('URL suffix in database:', result[0]['motm_url_suffix'] if result else 'No data')
"
Expected Behavior
When clicking "Save Settings":
- Form data is received ✅
- URL suffix is generated ✅
- UPDATE query executes ✅
- URL suffix is saved to database ✅
- Flash message shows the URL ✅
When clicking "Activate MotM Vote":
- Form data is received ✅
- URL suffix is retrieved from database ✅
- If missing, a new one is generated and saved ✅
- Flash message shows the URL ✅
Next Steps
- Deploy the updated code with debug logging
- Test the MOTM admin page and click "Save Settings"
- Check the logs for debug messages
- Share the debug output if the issue persists
- Verify the database using the manual verification command
Removing Debug Logging
Once the issue is resolved, you can remove the debug logging by searching for lines containing:
print(f"DEBUG:
And removing them, or I can create a cleaned-up version for you.
Support
If you continue to have issues after checking the debug logs:
- Save the complete debug output
- Check the application logs for any errors
- Verify the database connection is working
- Check if there are any database permission issues
- Share the debug output and any error messages