asolfre / appengine-rest-server

Automatically exported from code.google.com/p/appengine-rest-server
Other
0 stars 0 forks source link

Allow Queries on Dynamic Properties #50

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
GET Queries do not allow dynamic properties. This is a defect because the code 
raises an AttributeError that the method can_query() is not found.

I attached a GNU Diff files with changes to allow dynamic property queries. It 
is very functional, but consider fine tuning it.

It coerces the name=value string into native Python types using regular 
expressions. It does so w/o consulting the Property class (which is not 
possible here). Quotes string are an escape so that StringProperty values can 
otherwise match the REs.

Python Types
============
1) float: f=3.14 or f=2.0 (the dot and a nmber after is required.)
2) integet: f=12
3) datetime: Use your parse_date_time() function and DATE_TIME_FORMAT_NO_MS.
4) time: Use your parse_date_time() function and TIME_FORMAT_NO_MS, with 
leading "T".
5) Anything else is a unicode string.

ESCAPE RULE: types #1 to #4 can be in quotes: "3.14" or "T23:00:00" to be 
strings.

DataStore Query and Type
========================
Per GAE, the DataStore will only consider records where the dynamic property 
type matches the coerced Python type. The client must handle this.

Original issue reported on code.google.com by adroffner on 13 Jan 2012 at 6:54

Attachments:

GoogleCodeExporter commented 9 years ago
i'm curious, what is the use case for this?  for the most part, i figured that 
if a property was worth querying, it would be made into a real property instead 
of a dynamic property.  do you have situations where you have wildly varying 
models where you need to query the disparate properties?

using your type inference rules, how would you query a dynamic string property 
which contains a number value?

some alternatives to this which might be a little more robust:
- allow extra configuration on the model which indicates the type of some 
dynamic properties (e.g. "well known" dynamic properties), although you would 
probably just make them real properties
- add another query parameter which provides type information, e.g.: 
feq_some_prop=1.0&type_some_prop=float

Original comment by jahlborn@gmail.com on 13 Jan 2012 at 11:57

GoogleCodeExporter commented 9 years ago
There are really TWO points in this issue, a BUGFIX or an Enhancement.

1) MUST BUGFIX: There is a DynamicPropertyHandler BUG that causes the REST API 
to crash when someone tries a dynamic property query.
FIX: Add the can_query() method as shown below, with NO dynamic property query 
feature.

OR...

2)CAN MAKE Enhancement: Allow dynamic property queries with the full GNU Diff 
patch.
  a) This patch does allow dynamic string properties which contain a number values.
The number has quotes around it to "cast" as a string, when it matches the 
reg-ex already.
ESCAPE RULE: Values can be in quotes: "3.14" or "T23:00:00" to be strings.

  b) ONE DATATYPE: Yes, we may have wildly varying models, but only one datatype per property.
The DataStore query-system only considers values "of the same type" when it 
reads a query. So, property x can have some "strings" & some "integers, but 
feq_x=10 only matches the integer columns.

BUGFIX:
=======
class DynamicPropertyHandler(object):
    """PropertyHandler for dynamic properties on Expando models."""

    def __init__(self, property_name):
        self.property_name = property_name

    # .....

    def can_query(self):
        """If Dynamic properties cannot be used in query filters,
        then this method must return False.
        Otherwise, the code raises AttributeError.
        """
        return False

    # .....

Original comment by adroffner on 17 Jan 2012 at 5:23

GoogleCodeExporter commented 9 years ago
for some reason, when i wrote my original reply, i missed that you included the 
option to quote values to force interpreting them as strings.  

Original comment by jahlborn@gmail.com on 18 Jan 2012 at 3:53

GoogleCodeExporter commented 9 years ago

Original comment by jahlborn@gmail.com on 15 May 2012 at 12:17

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r71.

Original comment by jahlborn@gmail.com on 15 May 2012 at 2:54

GoogleCodeExporter commented 9 years ago
i've added support for querying on dynamic properties.  i'm not sure why your 
code used the "T" prefix on the time string.  i used the time format without 
the T prefix and added a date format match as well.

Original comment by jahlborn@gmail.com on 15 May 2012 at 2:54

GoogleCodeExporter commented 9 years ago

Original comment by jahlborn@gmail.com on 6 Jun 2012 at 1:04