Update app.py
Browse files
app.py
CHANGED
|
@@ -136,6 +136,8 @@ class SalesforceManager:
|
|
| 136 |
describe = self.sf.TreeInspection__c.describe()
|
| 137 |
for field in describe['fields']:
|
| 138 |
if field['name'] == 'Disease__c':
|
|
|
|
|
|
|
| 139 |
return field['updateable']
|
| 140 |
logging.warning("Disease__c field not found in object description.")
|
| 141 |
return False
|
|
@@ -394,13 +396,15 @@ def save_to_salesforce(tree_data, diagnosis_data, image):
|
|
| 394 |
max_retries = 3
|
| 395 |
for attempt in range(max_retries):
|
| 396 |
try:
|
| 397 |
-
#
|
| 398 |
disease_val = tree_data.get('disease', 'Unknown')
|
| 399 |
if not isinstance(disease_val, str):
|
| 400 |
disease_val = str(disease_val)
|
|
|
|
| 401 |
disease_val = disease_val.strip() # Remove leading/trailing whitespace
|
| 402 |
if len(disease_val) > 255:
|
| 403 |
-
|
|
|
|
| 404 |
logging.info(f"Attempt {attempt + 1}: Saving disease name: '{disease_val}'")
|
| 405 |
|
| 406 |
tree_record = {
|
|
|
|
| 136 |
describe = self.sf.TreeInspection__c.describe()
|
| 137 |
for field in describe['fields']:
|
| 138 |
if field['name'] == 'Disease__c':
|
| 139 |
+
if field['type'] != 'string' or field['length'] != 255:
|
| 140 |
+
logging.warning(f"Disease__c field type is {field['type']} with length {field['length']} instead of string(255)")
|
| 141 |
return field['updateable']
|
| 142 |
logging.warning("Disease__c field not found in object description.")
|
| 143 |
return False
|
|
|
|
| 396 |
max_retries = 3
|
| 397 |
for attempt in range(max_retries):
|
| 398 |
try:
|
| 399 |
+
# Sanitize and prepare disease name
|
| 400 |
disease_val = tree_data.get('disease', 'Unknown')
|
| 401 |
if not isinstance(disease_val, str):
|
| 402 |
disease_val = str(disease_val)
|
| 403 |
+
disease_val = ''.join(c for c in disease_val if c.isprintable()) # Remove non-printable characters
|
| 404 |
disease_val = disease_val.strip() # Remove leading/trailing whitespace
|
| 405 |
if len(disease_val) > 255:
|
| 406 |
+
logging.warning(f"Disease name '{disease_val}' truncated from {len(disease_val)} to 255 characters.")
|
| 407 |
+
disease_val = disease_val[:255]
|
| 408 |
logging.info(f"Attempt {attempt + 1}: Saving disease name: '{disease_val}'")
|
| 409 |
|
| 410 |
tree_record = {
|