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

pypgstac migrate Can't Be Used on Developer Versions of Postgres #300

Closed
MathewNWSH opened this issue Aug 29, 2024 · 2 comments
Closed

pypgstac migrate Can't Be Used on Developer Versions of Postgres #300

MathewNWSH opened this issue Aug 29, 2024 · 2 comments

Comments

@MathewNWSH
Copy link

Using the postgis/postgis:17beta3-master image:

eouser@pgstac-s2l2a:~$ pypgstac migrate
Traceback (most recent call last):
  File "/home/eouser/.local/bin/pypgstac", line 8, in <module>
    sys.exit(cli())
  File "/home/eouser/.local/lib/python3.10/site-packages/pypgstac/pypgstac.py", line 125, in cli
    fire.Fire(PgstacCLI)
  File "/home/eouser/.local/lib/python3.10/site-packages/fire/core.py", line 141, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "/home/eouser/.local/lib/python3.10/site-packages/fire/core.py", line 466, in _Fire
    component, remaining_args = _CallAndUpdateTrace(
  File "/home/eouser/.local/lib/python3.10/site-packages/fire/core.py", line 681, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "/home/eouser/.local/lib/python3.10/site-packages/pypgstac/pypgstac.py", line 61, in migrate
    return migrator.run_migration(toversion=toversion)
  File "/home/eouser/.local/lib/python3.10/site-packages/pypgstac/migrate.py", line 125, in run_migration
    pg_version = self.db.pg_version
  File "/home/eouser/.local/lib/python3.10/site-packages/pypgstac/db.py", line 280, in pg_version
    if int(version.split(".")[0]) < 13:
ValueError: invalid literal for int() with base 10: '17beta3 (Debian 17~beta3-1'

A "goofy" workaround that bypasses the issue by attempting to catch the ValueError and proceeding accordingly:

    @property
    def pg_version(self) -> str:
        """Get the current pg version number from a pgstac database."""
        version = self.query_one(
            """
            SHOW server_version;
            """,
        )
        logger.debug(f"PG VERSION: {version}.")
        if isinstance(version, bytes):
            version = version.decode()
        if isinstance(version, str):
            try:
                if int(version.split(".")[0]) < 13:
                    raise Exception("PgSTAC requires PostgreSQL 13 ")
                return version
            except ValueError:
                print("Warning: Developer version of PostgreSQL deteced")
                pass
        else:
            if self.connection is not None:
                self.connection.rollback()
            raise Exception("Could not find PG version.")
@stac-utils stac-utils deleted a comment Aug 29, 2024
@drnextgis
Copy link
Collaborator

The issue seems resolved with the changes in #304, so I believe it can be closed.

@vincentsarago
Copy link
Member

Oh I didn't see the issue 😓

I've fixed the version issue but I still think there is a bigger problem with pgstac and pg17.

I'll try to run the test with pg17 and open an issue later 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants