Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#29461 closed Bug (fixed)

ogrinspect test_time_field failure on SpatiaLite

Reported by: Tim Graham Owned by: nobody
Component: GIS Version: dev
Severity: Normal Keywords:
Cc: Claude Paroz Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

On Ubuntu 18.04, I see this test failure:

======================================================================
FAIL: test_time_field (gis_tests.inspectapp.tests.OGRInspectTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/media/sf_django/tests/gis_tests/inspectapp/tests.py", line 137, in test_time_field
    self.assertIn('    f_decimal = models.DecimalField(max_digits=0, decimal_places=0)', model_def)
AssertionError: '    f_decimal = models.DecimalField(max_digits=0, decimal_places=0)' not found in '# This is an auto-generated Django model module created by ogrinspect.\nfrom django.contrib.gis.db import models\n\n\nclass Measurement(models.Model):\n    f_decimal = models.CharField(max_length=0)\n    f_float = models.CharField(max_length=0)\n    f_int = models.IntegerField()\n    f_char = models.CharField(max_length=0)\n    f_date = models.DateField()\n    f_datetime = models.DateTimeField()\n    f_time = models.TimeField()\n    geom = models.PolygonField()'

Here's a diff that shows the actual results:

  • tests/gis_tests/inspectapp/tests.py

    diff --git a/tests/gis_tests/inspectapp/tests.py b/tests/gis_tests/inspectapp/tests.py
    index 51bb363..c63c841 100644
    a b class OGRInspectTest(TestCase):  
    134134        ))
    135135
    136136        # The ordering of model fields might vary depending on several factors (version of GDAL, etc.)
    137         self.assertIn('    f_decimal = models.DecimalField(max_digits=0, decimal_places=0)', model_def)
     137        self.assertIn('    f_decimal = models.CharField(max_length=0)', model_def)
    138138        self.assertIn('    f_int = models.IntegerField()', model_def)
    139139        self.assertIn('    f_datetime = models.DateTimeField()', model_def)
    140140        self.assertIn('    f_time = models.TimeField()', model_def)
    141         self.assertIn('    f_float = models.FloatField()', model_def)
    142         self.assertIn('    f_char = models.CharField(max_length=10)', model_def)
     141        self.assertIn('    f_float = models.CharField(max_length=0)', model_def)
     142        self.assertIn('    f_char = models.CharField(max_length=0)', model_def)
    143143        self.assertIn('    f_date = models.DateField()', model_def)
    144144
    145145        # Some backends may have srid=-1

I'm not sure if the test ever ran on SpatiaLite. On older versions of Ubuntu (16.04) the test is skipped. The original exception that's caught says "Could not open the datasource at "file:memorydb_default?mode=memory&cache=shared"". The behavior changed in GDAL 2.1.0.

Change History (6)

comment:1 by Claude Paroz, 6 years ago

For the DecimalField failure, we can use connection.features.can_introspect_decimal_field like in InspectDBTestCase.test_number_field_types.
For the other failures, I'm almost sure they are limitations of the GDAL SQLite introspection:

$ ogrinfo geodjango1.db inspectapp_allogrfields

Geometry Column 1 = geom
Geometry Column 2 = point
f_decimal: String (0.0) NOT NULL
f_float: String (0.0) NOT NULL
f_int: Integer (0.0) NOT NULL
f_char: String (0.0) NOT NULL
f_date: Date (0.0)
f_datetime: DateTime (0.0)
f_time: Time (0.0)

My opinion is that we should skip those tests on Spatialite waiting for GDAL introspection progress with this driver.
We could workaround those limitations by resorting to standard SQLite introspection for non-geometry fields, but I'm not sure if it's worth it.

comment:2 by Tim Graham, 6 years ago

Has patch: set

Would you do something different from this PR?

comment:3 by Tim Graham <timograham@…>, 6 years ago

Resolution: fixed
Status: newclosed

In f4bd1684:

[2.0.x] Fixed #29461 -- Fixed ogrinspect test_time_field failure on SpatiaLite.

Backport of 666be7b9942611d5c0f5e485c448f219cd5a1ad5 from master

comment:4 by Tim Graham <timograham@…>, 6 years ago

In cc8ef632:

[2.1.x] Fixed #29461 -- Fixed ogrinspect test_time_field failure on SpatiaLite.

Backport of 666be7b9942611d5c0f5e485c448f219cd5a1ad5 from master

comment:5 by Tim Graham <timograham@…>, 6 years ago

In 666be7b:

Fixed #29461 -- Fixed ogrinspect test_time_field failure on SpatiaLite.

comment:6 by Tim Graham <timograham@…>, 6 years ago

In b548180:

[1.11.x] Fixed #29461 -- Fixed ogrinspect test_time_field failure on SpatiaLite.

Backport of 666be7b9942611d5c0f5e485c448f219cd5a1ad5 from master

Note: See TracTickets for help on using tickets.
Back to Top