Goal: Parse an excel file uploaded to Retool storage eliminating some unnecessary columns / rows, transforming a date field, and returning the data to a table in my app.
Steps: I have a multi-page app that includes the ability for a user to upload an excel report from a customer for processing into a Postgres database (hosted in AWS). The button that captures the file has an event handler for uploaded to storage that calls the workflow I've built to handle the file parsing.
In the workflow, I have an inbound webhook setup, and the file is correctly identified post upload to Retool storage. The workflow is failing at the step it's attempting to read the uploaded file with the error "AttributeError: object has no attribute 'file'" even though the input clearly shows the file with the relevant data.
Details:
Here's the error:
Here is the code being executed in Python by the workflow step parseReport:
# Retool Workflow to process an uploaded Royaly Report with Python Pandas and return the data back to a table in the front end.
import pandas as pd
# Read the Excel file, skipping unnecessary rows and setting the 18th row as the header. startTrigger is the name of the inbound webhook in Retool Workflow that is called to execute this code.
df=pd.read_excel( {{ startTrigger.file[0].fileId }},sheet_name='ReportForm',skiprows=17,header=0)
df.drop(columns=['A'], inplace=True)
# Convert the "Reporting Period (Month/Yr)" column to datetime, assuming it's in 'MM/YY' format
df['Reporting Period (Month/Yr)'] = pd.to_datetime(df['Reporting Period (Month/Yr)'], format='%m/%y')
# Set the day to the last day of the month
df['Reporting Period (Month/Yr)'] = df['Reporting Period (Month/Yr)'] + pd.offsets.MonthEnd(0)
# Convert the datetime back to the desired format 'MM/DD/YYYY'
df['Reporting Period (Month/Yr)'] = df['Reporting Period (Month/Yr)'].dt.strftime('%m/%d/%Y')
Screenshots:
Workflow Libraries:
parseReport input showing file information:
Retool Storage showing file:
I have tried using the file name as well as the fileID to no effect. I am using a workflow to do this processing, rather than "in app" because I would like to extend this functionality in the future with more automation around the inbound file processing.
I have a time-sensitive project tied to this function - I'd really appreciate some quick help / insight here. Thanks.