Lookup query against a data table <date> column raises exception because the search parameter appears to be of type <unresolved>

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:

  1. 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.
  2. If the “start date” date picker is blank, then the form calls the server function get_oldest_row() which returns a date.
  3. 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 :slight_smile:

Hello, I didn’t have time to read everything in detail but I believe I have seen this error before when a column exists in the data table but its “type” has not been specified.

For example, if you have “create automatic columns” turned on in the data table interface, sometimes when adding rows new columns can get created without a type. Thus, when you try to write a date to that column, it says “hey I can’t store a date, my data type is not known (unresolved)”.

I have no idea if this is the issue, but I would check my date columns to make sure they are set to store dates (they shouldn’t say “unresolved”).

Again, this is just a guess.

Hi @alcampopiano. Thanks for taking a look - I don’t think that’s the issue (the problem isn’t writing data to a table, but performing a search on data already in there, and the self-same function works under other circumstances.

1 Like

Hi there,

When no start date is selected, what is the type of self.start_date just before you pass it to get_specific_rows?

I’ve done a little mock up app that does what you are describing (I think) and things work as expected:
https://anvil.works/build#clone:BMC6UMJ46PZXGL6I=FDVGTAEQIIHLBDKC76WSLHWT

Hopefully this will help you identify the issue.

If you are able, please share a small working example app that demonstrates the issue. This can often help folks here to more easily provide assistance.

2 Likes

Hi, thanks for the reply - I have been flat out at work since posting, and am just dashing off to work again now - so I will take another look when I can.

Richard your code excrepts look correct.
Campopianoa’s app works like a charm.
Can you please post the full code of your def button_search_dates_click function?

Thanks