From 8ab68dfac3f4e478b45aa564e91f1811f83db0fa Mon Sep 17 00:00:00 2001 From: Adrien Berchet Date: Mon, 13 Dec 2021 15:07:51 +0100 Subject: [PATCH 1/2] Fix cache warnings --- geoalchemy2/elements.py | 2 ++ geoalchemy2/functions.py | 9 ++++++++- geoalchemy2/types.py | 18 ++++++++++++++++++ tests/gallery/test_summarystatsagg.py | 4 ++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/geoalchemy2/elements.py b/geoalchemy2/elements.py index c34fe74e..29166c36 100644 --- a/geoalchemy2/elements.py +++ b/geoalchemy2/elements.py @@ -253,6 +253,8 @@ class CompositeElement(FunctionElement): Instances of this class wrap a Postgres composite type. """ + inherit_cache = True + def __init__(self, base, field, type_): self.name = field self.type = to_instance(type_) diff --git a/geoalchemy2/functions.py b/geoalchemy2/functions.py index e0f42ad9..df934965 100644 --- a/geoalchemy2/functions.py +++ b/geoalchemy2/functions.py @@ -75,6 +75,9 @@ def __init__(cls, clsname, bases, clsdict): class TableRowElement(ColumnElement): + + inherit_cache = True + def __init__(self, selectable): self.selectable = selectable @@ -88,6 +91,7 @@ class ST_AsGeoJSON(with_metaclass(_GenericMeta, functions.GenericFunction)): feature version introduced in PostGIS 3.""" name = "ST_AsGeoJSON" + inherit_cache = True def __init__(self, *args, **kwargs): expr = kwargs.pop('expr', None) @@ -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): diff --git a/geoalchemy2/types.py b/geoalchemy2/types.py index f5d81f9a..911f1d35 100644 --- a/geoalchemy2/types.py +++ b/geoalchemy2/types.py @@ -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): @@ -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): """ @@ -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): """ @@ -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 @@ -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 + """ Enable cache for this type. """ + # Register Geometry, Geography and Raster to SQLAlchemy's Postgres reflection # subsystem. @@ -403,3 +418,6 @@ class SummaryStats(CompositeType): 'min': Float, 'max': Float, } + + cache_ok = True + """ Enable cache for this type. """ diff --git a/tests/gallery/test_summarystatsagg.py b/tests/gallery/test_summarystatsagg.py index b58b7084..7fecc6ed 100644 --- a/tests/gallery/test_summarystatsagg.py +++ b/tests/gallery/test_summarystatsagg.py @@ -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 + engine = create_engine('postgresql://gis:gis@localhost/gis', echo=True) metadata = MetaData(engine) From a0b2ec437a06ff6f333bda896976af69c214c568 Mon Sep 17 00:00:00 2001 From: Adrien Berchet Date: Sat, 18 Dec 2021 15:57:03 +0100 Subject: [PATCH 2/2] zzzeek's suggestions --- geoalchemy2/elements.py | 2 +- geoalchemy2/functions.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/geoalchemy2/elements.py b/geoalchemy2/elements.py index 29166c36..0dc6d760 100644 --- a/geoalchemy2/elements.py +++ b/geoalchemy2/elements.py @@ -253,7 +253,7 @@ class CompositeElement(FunctionElement): Instances of this class wrap a Postgres composite type. """ - inherit_cache = True + inherit_cache = False def __init__(self, base, field, type_): self.name = field diff --git a/geoalchemy2/functions.py b/geoalchemy2/functions.py index df934965..11bacc96 100644 --- a/geoalchemy2/functions.py +++ b/geoalchemy2/functions.py @@ -76,7 +76,7 @@ def __init__(cls, clsname, bases, clsdict): class TableRowElement(ColumnElement): - inherit_cache = True + inherit_cache = False def __init__(self, selectable): self.selectable = selectable