Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cache warnings #338

Merged
merged 2 commits into from
Dec 24, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions geoalchemy2/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ class CompositeElement(FunctionElement):
Instances of this class wrap a Postgres composite type.
"""

inherit_cache = True

adrien-berchet marked this conversation as resolved.
Show resolved Hide resolved
def __init__(self, base, field, type_):
self.name = field
self.type = to_instance(type_)
Expand Down
9 changes: 8 additions & 1 deletion geoalchemy2/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ def __init__(cls, clsname, bases, clsdict):


class TableRowElement(ColumnElement):

inherit_cache = True

adrien-berchet marked this conversation as resolved.
Show resolved Hide resolved
def __init__(self, selectable):
self.selectable = selectable

Expand All @@ -88,6 +91,7 @@ class ST_AsGeoJSON(with_metaclass(_GenericMeta, functions.GenericFunction)):
feature version introduced in PostGIS 3."""

name = "ST_AsGeoJSON"
inherit_cache = True
adrien-berchet marked this conversation as resolved.
Show resolved Hide resolved

def __init__(self, *args, **kwargs):
expr = kwargs.pop('expr', None)
Expand Down Expand Up @@ -197,7 +201,10 @@ def __init__(self, *args, **kwargs):

# Iterate through _FUNCTIONS and create GenericFunction classes dynamically
for name, type_, doc in _FUNCTIONS:
attributes = {'name': name}
attributes = {
'name': name,
'inherit_cache': True,
}
docs = []

if isinstance(doc, tuple):
Expand Down
18 changes: 18 additions & 0 deletions geoalchemy2/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ class _GISType(UserDefinedType):
""" This is the way by which spatial operators are defined for
geometry/geography columns. """

cache_ok = False
""" Disable cache for this type. """

def __init__(self, geometry_type='GEOMETRY', srid=-1, dimension=2,
spatial_index=True, use_N_D_index=False, management=False, use_typmod=None,
from_text=None, name=None, nullable=True):
Expand Down Expand Up @@ -273,6 +276,9 @@ class Geometry(_GISType):
""" The element class to use. Used by the parent class'
``result_processor`` method. """

cache_ok = False
""" Disable cache for this type. """


class Geography(_GISType):
"""
Expand Down Expand Up @@ -302,6 +308,9 @@ class Geography(_GISType):
""" The element class to use. Used by the parent class'
``result_processor`` method. """

cache_ok = False
""" Disable cache for this type. """


class Raster(_GISType):
"""
Expand Down Expand Up @@ -344,6 +353,9 @@ class Raster(_GISType):
""" The element class to use. Used by the parent class'
``result_processor`` method. """

cache_ok = False
""" Disable cache for this type. """

def __init__(self, *args, **kwargs):
# Enforce default values
kwargs['geometry_type'] = None
Expand Down Expand Up @@ -385,6 +397,9 @@ class GeometryDump(CompositeType):
typemap = {'path': postgresql.ARRAY(Integer), 'geom': Geometry}
""" Dictionary defining the contents of a ``geometry_dump``. """

cache_ok = True
adrien-berchet marked this conversation as resolved.
Show resolved Hide resolved
""" Enable cache for this type. """


# Register Geometry, Geography and Raster to SQLAlchemy's Postgres reflection
# subsystem.
Expand All @@ -403,3 +418,6 @@ class SummaryStats(CompositeType):
'min': Float,
'max': Float,
}

cache_ok = True
adrien-berchet marked this conversation as resolved.
Show resolved Hide resolved
""" Enable cache for this type. """
4 changes: 4 additions & 0 deletions tests/gallery/test_summarystatsagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ class SummaryStatsCustomType(CompositeType):
'max': Float,
}

cache_ok = True


class ST_SummaryStatsAgg(GenericFunction):
type = SummaryStatsCustomType
# Set a specific identifier to not override the actual ST_SummaryStatsAgg function
identifier = "ST_SummaryStatsAgg_custom"

inherit_cache = True
adrien-berchet marked this conversation as resolved.
Show resolved Hide resolved


engine = create_engine('postgresql://gis:gis@localhost/gis', echo=True)
metadata = MetaData(engine)
Expand Down