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

pgbedrock errors on usernames with hyphens if that user also has a personal schema #43

Open
Gastove opened this issue Jul 20, 2018 · 6 comments

Comments

@Gastove
Copy link

Gastove commented Jul 20, 2018

Given a user:

captain-planet:
    has_personal_schema: true

The following error is returned by Postgres:


18-Jul-2018 19:57:19 | -- Skipping privilege configuration for user "captain-planet"": syntax error at or near "-"
-- | --
18-Jul-2018 19:57:19 | LINE 3:     ALTER DEFAULT PRIVILEGES IN SCHEMA captain-planet GRANT...

pgbedrock should be fully quoting captain-planet, which it does many places, but not, alas, enough places.

Gastove pushed a commit that referenced this issue Jul 20, 2018
Currently, certain `ALTER... SCHEMA` statements will fail if they address a
schema whose name contains a hyphen, which can happen, for instance, managing
the personal schema of a user whose name contains a hyphen. This commit wraps
the schema name in quotes for the two affected sql queries, and bumps pgbedrock
to 0.3.2.

Closes #43.
@zcmarine
Copy link
Contributor

Hey Ross, greetings from the other side. :)

Yeah, this is a known bug and is recorded in issue #7. As a result, I'm closing this issue as a duplicate.

I think this should be doable to solve. It requires changing how an ObjectName instance's qualified_name is rendered (which is just an if-else), but the reason I didn't address it when implementing ObjectNames in the first place was a wrinkle in loading the YAML, as noted in this comment.

If you'd like to take a crack at it, please do! Otherwise it'll probably stay an open issue for a while. I'm happy to sync though if there's interest.

@Gastove
Copy link
Author

Gastove commented Jul 20, 2018

Hey @zmarine! I hope things on the other side are well.

Unless I'm missing something, I think this issue is a more limited sub-issue of #7; I believe this issue should be adequately addressed by #44. While I'm also game to take on #7, it seems like it lays the groundwork for fully-qualified objects (e.g. "foo-schema"."foo-table") as well as improving this handling. Do you disagree?

@Gastove
Copy link
Author

Gastove commented Jul 20, 2018

Perhaps more generally: it seems there's some confusion here in how we expect quotes to be applied around objects that need them. In many places, quotes are provided in the query template strings themselves; #44 addresses this by adding them in even more places. #7 seems like it requires re-factoring quote handling to make it the responsibility of an object to know how it should be rendered (though, most of the time, a "quote all the things" approach is likely to be both safe and harmless).

@zcmarine
Copy link
Contributor

Hey Ross, that makes some sense to me. My one concern is whether you could then end up in a state where pgbedrock configure operates on a spec that can't be generated by pgbedrock generate. I'm not sure about that, but I suppose you could add a test that adds a role and adds a personal schema, and see if pgbedrock generate works.

I'll be heading to Ethiopia today and likely won't be online much, so from my perspective if you can verify that both the generate and configure components work with dashes then feel free to merge. I'm not sure if anyone else is an admin in this repo yet, but if not they probably should be.

@Gastove
Copy link
Author

Gastove commented Jul 26, 2018

Unless I'm misreading something, we have a test for this already, which has been passing this whole time: oh boy

@Gastove Gastove reopened this Jul 26, 2018
@Gastove
Copy link
Author

Gastove commented Jul 27, 2018

So: we have a test that makes this claim:

def test_configure_schema_role_has_dash(tmpdir, capsys, db_config, cursor, base_spec):
    """
    We add a new user ('role-with-dash') through pgbedrock and make sure that that user can create
    a personal schema
    """

However: the test case is too small. It isn't until a certain threshold of complexity is hit that pgbedrock sets default role grants; it isn't until those grants are set that any of this becomes a problem.

I've added a test for this failure case; I'm going to push it to the branch with an open PR so the failing case can be tracked. My existing solution is definitely not enough.

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

2 participants