210 lines
5.3 KiB
Markdown
210 lines
5.3 KiB
Markdown
# 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:
|
|
|
|
1. **When the form is submitted:**
|
|
- Which button was clicked (Save vs Activate)
|
|
- What form data was received
|
|
|
|
2. **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
|
|
|
|
3. **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:
|
|
|
|
```bash
|
|
# 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
|
|
|
|
1. Go to https://motm.ervine.cloud/admin/motm
|
|
2. Fill in the form:
|
|
- Match date
|
|
- Opposition team
|
|
- Current MOTM (optional)
|
|
- Current DotD (optional)
|
|
- Voting deadline (optional)
|
|
3. Click **"Save Settings"** button
|
|
4. Check the logs
|
|
|
|
### Step 3: Check the Logs
|
|
|
|
```bash
|
|
# 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:
|
|
|
|
```bash
|
|
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 `userid` column has the value 'admin'
|
|
- Run the diagnostic script: `check_production_db.py`
|
|
|
|
## Manual Verification
|
|
|
|
After clicking "Save Settings", verify the URL suffix was saved:
|
|
|
|
```bash
|
|
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":
|
|
1. Form data is received ✅
|
|
2. URL suffix is generated ✅
|
|
3. UPDATE query executes ✅
|
|
4. URL suffix is saved to database ✅
|
|
5. Flash message shows the URL ✅
|
|
|
|
### When clicking "Activate MotM Vote":
|
|
1. Form data is received ✅
|
|
2. URL suffix is retrieved from database ✅
|
|
3. If missing, a new one is generated and saved ✅
|
|
4. Flash message shows the URL ✅
|
|
|
|
## Next Steps
|
|
|
|
1. **Deploy the updated code** with debug logging
|
|
2. **Test the MOTM admin page** and click "Save Settings"
|
|
3. **Check the logs** for debug messages
|
|
4. **Share the debug output** if the issue persists
|
|
5. **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:
|
|
```python
|
|
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:
|
|
|
|
1. Save the complete debug output
|
|
2. Check the application logs for any errors
|
|
3. Verify the database connection is working
|
|
4. Check if there are any database permission issues
|
|
5. Share the debug output and any error messages
|
|
|