Closed retr0h closed 4 years ago
Actually, this looks to be a problem with pip install in general.
[jodewey:~] % mkdir foo
[jodewey:~] % cd foo
[jodewey:~/foo] % virtualenv --no-site-packages .venv
Using base prefix '/Users/jodewey/.pyenv/versions/3.7.6'
New python executable in /Users/jodewey/foo/.venv/bin/python3.7
Also creating executable in /Users/jodewey/foo/.venv/bin/python
Installing setuptools, pip, wheel...
done.
[jodewey:~/foo] % source .venv/bin/activate
[jodewey:~/foo] % pip install pq
Processing /Users/jodewey/Library/Caches/pip/wheels/bb/9a/57/391012c0c104963cc3c6575f90af34d951eb5b123179bfe9c9/pq-1.8.1-py3-none-any.whl
Installing collected packages: pq
Successfully installed pq-1.8.1
[jodewey:~/foo] % find . -name "create.sql"
./.venv/lib/python3.7/site-packages/pq/create.sql
[jodewey:~/foo] % cat ./.venv/lib/python3.7/site-packages/pq/create.sql
do $$ begin
CREATE TABLE %(name)s (
id bigserial PRIMARY KEY,
enqueued_at timestamptz NOT NULL DEFAULT current_timestamp,
dequeued_at timestamptz,
expected_at timestamptz,
schedule_at timestamptz,
q_name text NOT NULL CHECK (length(q_name) > 0),
data json NOT NULL
);
end $$ language plpgsql;
create index priority_idx_%(name)s on %(name)s
(schedule_at nulls first, expected_at nulls first, q_name)
where dequeued_at is null
and q_name = '%(name)s';
create index priority_idx_no_%(name)s on %(name)s
(schedule_at nulls first, expected_at nulls first, q_name)
where dequeued_at is null
and q_name != '%(name)s';
drop function if exists pq_notify() cascade;
create function pq_notify() returns trigger as $$ begin
perform pg_notify(new.q_name, '');
return null;
end $$ language plpgsql;
create trigger pq_insert
after insert on %(name)s
for each row
execute procedure pq_notify();
@retr0h, could you please help us understand what exactly is the issue here?
The error you're getting looks pretty straight-forward:
psycopg2.errors.DuplicateTable: relation "queue" already exists
I recently had to set up pq
with django and there's a simple way to work around this:
https://github.com/occrp/id-backend/commit/0e0b5f9421996eb4b2f93aaf5f84511baf2031b8#diff-1066dd485a7c75c339cc3bd577b45328
@stas The issue is the create.sql
file in the pypi package 1.8.1
, does not contain the same contents in the pq repo's master branch.
For some reason when the author tags the repo and creates a release, the create.sql
is not being updated.
create.sql
:
The file in master branch has conditions in the sql create table if not exists %(name)s
, where this schema file would be safe to run multiple times.
The error you're getting looks pretty straight-forward:
psycopg2.errors.DuplicateTable: relation "queue" already exists
I recently had to set up pq with django and there's a simple way to work around this: occrp/id-backend@0e0b5f9#diff-1066dd485a7c75c339cc3bd577b45328
You are working around the very problem I am discussing in this issue.
@malthe do you think you can release a new version, because it looks like the tag v1.8.1 is not including the latest changes in the SQL file the @retr0h is mentioning.
@retr0h, the tag v1.8.1 actually does not include the changes, so I think we should just release the master under v1.8.2 and it should solve the issue: https://github.com/malthe/pq/blob/1.8.1/pq/create.sql
Thanks for being patient with us :bow: :see_no_evil:
I have released 1.8.2. Sorry for the wait!
Expected Behavior
PQ.create()
is idempotentActual Behavior
Subsequent calls to
PQ.create()
fails.Steps to Reproduce the Problem
mkdir pq-pipenv && cd pq-pipenv
pipenv --python 3.7
pipenv install pq psycopg2-binary
pipenv run pip freeze
test.py
pipenv run python test.py
.After further investigation the
create.sql
file in the virtualenv is old. It does not contain the version from 1.8.1.Specifications