Skip to content

Commit

Permalink
Updated to work with pyscopg2 version 2.9.1
Browse files Browse the repository at this point in the history
Fixes gravitystorm#4447

Tested against psycopg2 versions 2.8.6 and 2.9.1
  • Loading branch information
frankdean committed Aug 23, 2021
1 parent eed4caf commit cad7f41
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions scripts/get-external-data.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def clean_temp(self):
with self._conn.cursor() as cur:
cur.execute('''DROP TABLE IF EXISTS "{temp_schema}"."{name}"'''
.format(name=self._name, temp_schema=self._temp_schema))
self._conn.commit()
self._conn.commit()

# get the last modified date from the metadata table
def last_modified(self):
Expand All @@ -64,6 +64,7 @@ def last_modified(self):
results = cur.fetchone()
if results is not None:
return results[0]
self._conn.commit()

def grant_access(self, user):
with self._conn.cursor() as cur:
Expand Down Expand Up @@ -98,7 +99,7 @@ def index(self):
# matter since it'll never need a vacuum.
cur.execute('''ALTER TABLE "{temp_schema}"."{name}" RESET ( autovacuum_enabled );'''
.format(name=self._name, temp_schema=self._temp_schema))
self._conn.commit()
self._conn.commit()

# VACUUM can't be run in transaction, so autocommit needs to be turned on
old_autocommit = self._conn.autocommit
Expand Down Expand Up @@ -188,11 +189,12 @@ def main():

renderuser = opts.renderuser or config["settings"].get("renderuser")

with requests.Session() as s, \
psycopg2.connect(database=database,
with requests.Session() as s:
conn = None
conn = psycopg2.connect(database=database,
host=host, port=port,
user=user,
password=password) as conn:
password=password)

s.headers.update({'User-Agent': 'get-external-data.py/osm-carto'})

Expand Down Expand Up @@ -288,6 +290,8 @@ def main():
else:
logging.info(
"Table {} did not require updating".format(name))
if conn:
conn.close()


if __name__ == '__main__':
Expand Down

0 comments on commit cad7f41

Please sign in to comment.