Improve regex parsing of CHECK constraints.#5044
Conversation
zzzeek
left a comment
There was a problem hiding this comment.
looks good, lets use fixtures for the test case. thanks!
|
The beginning of the test now looks like this: @testing.provide_metadata
def test_reflect_check_constraint(self):
meta = self.metadata
udf_create = """\
CREATE OR REPLACE FUNCTION is_positive(
x integer DEFAULT '-1'::integer)
RETURNS boolean
LANGUAGE 'plpgsql'
COST 100
VOLATILE
AS $BODY$BEGIN
RETURN x > 0;
END;$BODY$;
"""
sa.event.listen(meta, "before_create",
sa.DDL(udf_create))
sa.event.listen(meta, "after_drop",
sa.DDL("DROP FUNCTION is_positive"))
cc_table = Table(
"pgsql_cc",
meta,
Column("a", Integer()),
CheckConstraint("a > 1 AND a < 5", name="cc1"),
CheckConstraint("a = 1 OR (a > 2 AND a < 5)", name="cc2"),
CheckConstraint("is_positive(a)", name="cc3"),
)
cc_table.create()Unfortunately, the CREATE FUNCTION is not getting sent (at all; see attached log), so the CREATE TABLE fails. However, the DROP FUNCTION is getting sent, so that fails, too. |
|
yes call metadata.create_all() instead of table.create() |
|
Yup, that did the trick. Thanks. |
|
are you interested in writing changelog files ? |
Sure, I could give it a bash. Just create a 5039.rst file? Right now it looks like they all live in the unreleased_14 folder. |
|
OK so, this is a bug that we are targeting at 1.3.x, so it goes into unreleased_13. but yes thanks! |
sqla-tester
left a comment
There was a problem hiding this comment.
OK, this is sqla-tester setting up my work to try to get revision b6903c6 of this pull request into gerrit so we can run tests and reviews and stuff
|
New Gerrit review created for change b6903c6: https://gerrit.sqlalchemy.org/#/c/sqlalchemy/sqlalchemy/+/1623 |
|
mike bayer (zzzeek) wrote: so on older Posgresql 9.6, we're getting this error: psycopg2.errors.SyntaxError: syntax error at end of input does CREATE FUNCTION / DROP FUNCTION not exist on PG 9? we can add an exclusion rule to the test if this is the case. |
|
Ah, it appears that DROP FUNCTION is_positive(integer)works in 12.1 and it should work in 9.6 as well. |
|
Gord Thompson (gordthompson) wrote: The pep8/1843 failure "F841 local variable 'cc_table' is assigned to but never used" looks like a new rule. (I have already found the one bloody space that triggered the "trailing whitespace" failure, which also appears to be a new rule.) The sqlalchemy_gerrit/3577 failure looks like a transient. |
F841 has been in for awhile. I'm working on F821 in https://gerrit.sqlalchemy.org/#/c/sqlalchemy/sqlalchemy/+/1649/ but F841 was in since 190e013 |
|
Yup, you're right. We had to change |
|
mike bayer (zzzeek) wrote: Code-Review+2 Workflow+1 |
|
Gerrit review https://gerrit.sqlalchemy.org/1623 has been merged. Congratulations! :) |
|
mike bayer (zzzeek) wrote: Code-Review+2 Workflow+1 |
|
Gerrit review https://gerrit.sqlalchemy.org/1672 has been merged. Congratulations! :) |
Fixed issue where the PostgreSQL dialect would fail to parse a reflected CHECK constraint that was a boolean-valued function (as opposed to a boolean-valued expression). Fixes: #5039 Closes: #5044 Pull-request: #5044 Pull-request-sha: b6903c6 Change-Id: I7d39b104a8ce346cb593d541c1b4e5eab88867f9 (cherry picked from commit d8ac1e9)
Fixes: #5039
Description
Avoid parse warnings for PostgreSQL CHECK constraints that are a simple function call.
Checklist
This pull request is:
must include a complete example of the issue. one line code fixes without an
issue and demonstration will not be accepted.
Fixes: #<issue number>in the commit messageinclude a complete example of how the feature would look.
Fixes: #<issue number>in the commit messageHave a nice day!