geopython / pycsw

pycsw is an OGC CSW server implementation written in Python. pycsw fully implements the OpenGIS Catalogue Service Implementation Specification [Catalogue Service for the Web]. Initial development started in 2010 (more formally announced in 2011). The project is certified OGC Compliant, and is an OGC Reference Implementation. pycsw allows for the publishing and discovery of geospatial metadata via numerous APIs (CSW 2/CSW 3, OpenSearch, OAI-PMH, SRU). Existing repositories of geospatial metadata can also be exposed, providing a standards-based metadata and catalogue component of spatial data infrastructures. pycsw is Open Source, released under an MIT license, and runs on all major platforms (Windows, Linux, Mac OS X). Please read the docs at https://pycsw.org/docs for more information.
https://pycsw.org
MIT License
210 stars 155 forks source link

Store datetime fields with a Datetime type instead of a string #365

Open ricardogsilva opened 9 years ago

ricardogsilva commented 9 years ago

Currently pycsw sets up a database using the sqlalchemy.Text type for most columns.

In my opinion it would be nicer if we could use other sqlalchemy types, specially the sqlalchemy.DateTime type when creating the database. This would make the transition from python datetimes to the database smoother. The current situation gets around this by trying not to use python datetime and using strings instead.

For an example, the pycsw.core.metadata._parse_sos method actually converts a python datetime object (as returned by owslib.sos.SensorObservationService.contents[...].begin_position) into a string (lines number 718 and 719), so that it can be manipulated further down the road.

There is also a safeguard in pycsw.core.util.getqattr to always convert a datetime.date or datetime.datetime to a string. This function is used whenever something is to be written to the database.

I propose that we change this around:

Benefits:

I have an initial draft with the changes necessary for implementing this proposal in my local repository. It seems to work OK with sqlite and postgis, but I can only test with normal records. I will prepare a pull request so that it may be evaluated.

kalxas commented 9 years ago

This proposal breaks backward compatibility to our existing deployments, so it is not that easy to handle. Similar discussion has happened in the early days of pycsw and we chose text representation as a simple/safe way to implement things. It would require something more than a PR, it would need an RFC and a vote from the steering committee to do such a change.

ricardogsilva commented 9 years ago

OK, I will investigate a bit more on alternative solutions and look at how other projects are doing this. I'll prepare an RFC if it will seem to be a worthy change

kalxas commented 9 years ago

I would recommend to post the above to the pycsw-devel mailing list for further discussion.