Commit Graph

19 Commits

Author SHA1 Message Date
Kenneth Kehl
905df17f65 remove datetime.utcnow() 2024-05-23 13:59:51 -07:00
Aditi Anand
df2a590f1a Merge branch 'notify-api-869' into aanand-sqlalchemy-version-update 2024-04-24 16:11:03 -04:00
Kenneth Kehl
ebdb78e52e reformat up to latest version of black 2024-04-01 15:12:33 -07:00
Aditi Anand
8bc1091f73 fix for failing tests 2024-03-20 10:57:04 -04:00
Aditi Anand
385ec3583f Initial commit for sqlalchemy2.0 migration 2024-03-13 12:42:11 -04:00
Kenneth Kehl
1ecb747c6d reformat 2023-08-29 14:54:30 -07:00
Kenneth Kehl
e037df8cbc notify-api-413 reduce cyclomatic complexity identified by radon 2023-08-16 09:29:32 -07:00
Ben Thorner
a91fde2fda Run auto-correct on app/ and tests/ 2021-03-12 11:45:45 +00:00
Alexey Bezhan
17f5742e2c Use model constructors when creating history instances
`create_history` used to initialise an empty model instance and
assign attributes to it one by one. Assigned attributes are
collected by iterating over internal state of the modified record
and stored in a dictionary, so the order in which they are set on
the history instance is undefined.

This works fine for most model instances, but recent changes to the
Template models require `template_type` to be set before `reply_to`,
otherwise Template doesn't know which column to use to persist the
`reply_to` value.

This means that we need to order the attributes when they're being
assigned. We achieved this by defining a constructor for Template
objects that assigns `template_type` first.

In order to make it work with `create_history` we replace individual
`setattr` calls with a single call to the Template constructor which
passes the entire data dictionary as keyword arguments.

This works because all persisted attributes are defined as columns
and SQLAlchemy accepts all column values as constructor arguments.
2017-11-30 10:57:13 +00:00
Leo Hemsted
28088428f1 flake8 - misc flake8 errs.
* unused variables
* variables in loops overshadowing imports
* excepts with no defined exc type (tried to avoid `except Exception` too)
* history mapper is still too complex
* default variables should never be mutable
2017-11-28 14:28:01 +00:00
Alexey Bezhan
559639eb63 Verify that attribute exists on *History model when versioning objects
When createing a history instance of the updated object `create_history`
sets attributes using `setattr`. Since SQLAlchemy model instances are
Python objects they don't prevent new attributes being created by setattr,
which means that if history models are missing some of the columns the
attributes will still be assigned, but their values will not be persisted
by SQLAlchemy since database columns for them do not exist.

To avoid this, we check that the attribute is defined on the `history_cls`
and raise an error if it isn't.
2017-11-22 14:15:58 +00:00
Leo Hemsted
26d7675baa pep8 fixes
no idea why the build/local pep8s weren't picking them up before.

also excluded import order pep8
2016-08-23 12:05:47 +01:00
Leo Hemsted
049514d4b2 remove history-meta for templates, replace with hand-made history table
history-meta's dynamic magic is insufficient for templates, where we
need to be able to refer to the specific history table to take
advantage of sqlalchemy's relationship management (2/3rds of an ORM).
So replace it with a custom made version table.

Had to change the version decorator slightly for this
2016-08-09 16:56:43 +01:00
Leo Hemsted
8e46cd44fd make history meta handle nullable and default better
* can now handle nullable foreign keys - would previously raise
  AttributeError
* can now handle default values - we would previously not insert
  default values that hadn't been generated yet, which if the
  field is not nullable will result in IntegrityErrors. We were
  deliberately removing 'default' attributes from columns. Only
  remove them if nullable is set to true now.
2016-08-09 15:59:22 +01:00
Nicholas Staples
1797d9360b Update template json to return created_at and updated_at. Also fixed a bug where updated_at was not being added to the templates_history model. 2016-05-19 17:02:55 +01:00
Nicholas Staples
03f15d6af9 Update now to utcnow. All tests passing. 2016-05-11 10:56:24 +01:00
Nicholas Staples
b56e324a4c Working tests and provider stats table.
Fix for tests and import error.

Added tests and updated for code review comments.
2016-04-25 12:20:06 +01:00
Adam Shimali
74ac5b5f30 Added version history to api keys. This needed a bit of change
to create history to handle foreign keys better. There may yet
be a better way of doing this that I have not found yet in sqlalchemy
docs.
2016-04-21 14:47:58 +01:00
Adam Shimali
a6a18c1a6f This approach uses part of sqlalchemy example history_meta code
adapted to recording inserts and updates.

This removes need to manually create history tables.

Our code still remains in control of when history records are
created.
2016-04-19 17:13:26 +01:00