-
Notifications
You must be signed in to change notification settings - Fork 12
Add notify method #2
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
base: master
Are you sure you want to change the base?
Conversation
ebd9f0c to
35246b3
Compare
pgnotify/__init__.py
Outdated
| """ | ||
| connection = get_dbapi_connection(connection) | ||
| cursor = connection.cursor() | ||
| cursor.execute("NOTIFY %s, '%s';" % (channel, payload)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is vulnerable to SQL-injection (correct me if I'm wrong 😉). Is there a way to fix this? If not, it should be explicitly stated in the documentation that untrusted payloads / channels aren't supported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I know Psycopg2’s execute method will sanitizes the arguments if passed as a tuple to the method.
For example
conn.execute(“NOTIFY %s, %s”, (channel, payload))
I’m not sure about sqlalchemy though :)
Look forward to this PR be merged! Looks neat and the library can be more complete with this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also it seems to be better to use the pg_notify function in Postgres for sending notifications to non-constant channel names and payloads?
Refer to the Notes section in the doc: https://www.postgresql.org/docs/9.0/sql-notify.html
|
Thank you kindly for this PR! Definitely a much-needed addition to this library. Some things will need changing before we merge:
|
This patch adds a method for sending a PostgreSQL notify with a payload to a specific channel.
670651d to
bc7c6be
Compare
This patch adds a method for sending a PostgreSQL notify with a payload
to a specific channel.