-
Notifications
You must be signed in to change notification settings - Fork 31
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
SQLAlchemy: Add support for 'autogenerate_uuid' in column creation #580
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -311,3 +311,36 @@ | |
'pk STRING NOT NULL, \n\t' | ||
'answer INT DEFAULT 42, \n\t' | ||
'PRIMARY KEY (pk)\n)\n\n'), ()) | ||
|
||
def test_column_autogenerate_uuid(self): | ||
class DummyTable(self.Base): | ||
Check notice Code scanning / CodeQL Unused local variable Note test
Variable DummyTable is not used.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please forget about those, they are just false positives, and can neither be suppressed, nor remedied otherwise. ReferencesThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aha. @aibaars just mentioned at github/codeql#11427 (comment):
Thanks! We may want to give it a shot, depending on mood and time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure. Using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes they should work, and plain |
||
__tablename__ = 't' | ||
pk = sa.Column(sa.String, primary_key=True, crate_autogenerate_uuid=True) | ||
other = sa.Column(sa.Boolean) | ||
|
||
self.Base.metadata.create_all(bind=self.engine) | ||
fake_cursor.execute.assert_called_with( | ||
'\nCREATE TABLE t (\n\t' | ||
'pk STRING DEFAULT gen_random_text_uuid() NOT NULL, \n\t' | ||
'other BOOLEAN, \n\tPRIMARY KEY (pk)\n)\n\n', () | ||
) | ||
|
||
def test_column_autogenerate_uuid_correct_type(self): | ||
class DummyTable(self.Base): | ||
Check notice Code scanning / CodeQL Unused local variable Note test
Variable DummyTable is not used.
|
||
__tablename__ = 't' | ||
pk = sa.Column(sa.Integer, primary_key=True, crate_autogenerate_uuid=True) | ||
other = sa.Column(sa.Boolean) | ||
|
||
with self.assertRaises(sa.exc.CompileError): | ||
self.Base.metadata.create_all(bind=self.engine) | ||
|
||
def test_column_autogenerate_uuid_clashes_with_server_default(self): | ||
class DummyTable(self.Base): | ||
Check notice Code scanning / CodeQL Unused local variable Note test
Variable DummyTable is not used.
|
||
__tablename__ = 't' | ||
pk = sa.Column(sa.String, primary_key=True, | ||
crate_autogenerate_uuid=True, | ||
server_default='value') | ||
Comment on lines
+341
to
+342
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, using both |
||
other = sa.Column(sa.Boolean) | ||
|
||
with self.assertRaises(sa.exc.CompileError): | ||
self.Base.metadata.create_all(bind=self.engine) |
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.
Doesn't
id = sa.Column(sa.String, primary_key=True, server_default=func.gen_random_text_uuid())
already work? Why do we need a custom property?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.
You are having a valid point here. Maybe the
crate_autogenerate_uuid
should be a table- or dialect-level parameter instead, to cover situations like outlined in GH-575, which is a slightly different topic, and can be deferred to another patch.If the user can write their own model definitions, your proposal to use
server_default=func.gen_random_text_uuid()
indeed would be completely satisfactory.So, the outcome for this topic could be essentially to cover that detail about
func.gen_random_text_uuid()
within the documentation and software tests atand not add any specific functionality for this on the column level. Apologies that GH-533 was giving wrong guidance here.