Hi. firstly, this has turned into a bit of an essay - sorry - I wanted to provide all the relevant info.
I have a form called Admin which has (amongst other things) two date picker components. These give the lower and upper bounds when searching a data table for records by date - I have a server function which runs the query and returns the results:
@anvil.server.callable
def get_specific_rows(start_date, end_date):
print "From get_specific_rows"
print type(start_date) # for diagnostics
print start_date # for diagnostics
results = app_tables.weight_data.search(
weigh_in_date = q.between(start_date, end_date, min_inclusive=True, max_inclusive = True)
)
data = []
for row in results:
data.append(
{'weigh_in_date': row['weigh_in_date'],
'weight_lbs': row['weight_lbs'],
'row_id': row.get_id()
})
return data
This all works fine when both date picker components have dates picked. However, I also want a feature where if the user leaves the “start” date picker blank, then it should default to the earliest record:
def button_search_dates_click(self, **event_args):
"""This method is called when the button is clicked"""
if not self.date_picker_start.date:
self.start_date = anvil.server.call('get_oldest_row')
The code above states that if the date is not picked, then server module get_oldest_row
should run:
@anvil.server.callable
def get_oldest_row():
# returns the date of the oldest weigh in
rows = get_weight_history() # A simple data table lookup
return rows[0]['weigh_in_date']
So the flow should be:
- If both date pickers are populated, the server function get_specific_rows() is called by the form, and returns a search iterator. This currently works fine.
- If the “start date” date picker is blank, then the form calls the server function
get_oldest_row()
which returns a date. - The form executes the server function ```get_specific_rows() using either the date from the date picker, or the looked up earliest date as the first argument (I haven’t put the “default” behaviour into the second argument yet). The function returns a search iterator.
What actually happens, when the first date picker is left blank, is this:
anvil.tables.TableError: Invalid query: Cannot query date column 'weigh_in_date' with a value of type unresolved
Which I don’t understand. If you look at the code for get_specific_rows()
above, you’ll see two diagnostic print() statements. The output from those statements clearly shows that the start_date
variable is of type datetime.date
- which is what I’d expect:
From get_specific_rows
<class 'datetime.date'>
2019-02-06
The very next line after those print statements is the one that raises the exception above, because it thinks that start_type is “unresolved”. Help - I don’t understand