jsor / doctrine-postgis

Spatial and Geographic Data with PostGIS and Doctrine.
MIT License
209 stars 50 forks source link

Geometry type is not loaded on production environment only #66

Closed thomas-dion-113 closed 8 months ago

thomas-dion-113 commented 8 months ago

In our Symfony instance (5.4) with the 1.8 version of the library, we didn’t define types in config/packages/doctrine.yaml like this :

doctrine:
    dbal:
        types:
            geography:
                class: 'Jsor\Doctrine\PostGIS\Types\GeographyType'
                commented: false
            geometry:
                class: 'Jsor\Doctrine\PostGIS\Types\GeometryType'
                commented: false

In dev and preprod environments, these types were loaded anyway and no error occurred. When we deployed in the production environment, error occurred because these types were not loaded :

Fatal error: Uncaught Doctrine\DBAL\Exception: Unknown column type "geometry" requested. Any Doctrine type that you use has to be registered with
\Doctrine\DBAL\Types\Type::addType(). You can get a list of all the known types with \Doctrine\DBAL\Types\Type::getTypesMap(). If this error occurs
during database introspection then you might have forgotten to register all database types for a Doctrine Type. Use
AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement Type#getMappedDatabaseTypes(). If the type name is empty
you might have a problem with the cache or forgot some mapping information. in
/var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php on line 282

Today, we have defined the types in the doctrine config file, so everything works. But we wanted to give you feedback because if it wasn’t very critical in our case, it could have been.

I think the behavior should be the same on all environments so there are 2 options here :

By the way, thanks for this great library.

jsor commented 8 months ago

Thanks for the report! Registering the DBAL types was already recommended. I've changed the wording in b0ddae205f01f52fd1e466d8588c889d70facc85.