mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-26 13:18:31 +08:00
BUG: Adds version checking to AssetFinder init
This commit is contained in:
@@ -1333,3 +1333,24 @@ class TestAssetDBVersioning(TestCase):
|
||||
# Assert that trying to overwrite the version fails
|
||||
with self.assertRaises(sa.exc.IntegrityError):
|
||||
write_version_info(version_table, -3)
|
||||
|
||||
def test_finder_checks_version(self):
|
||||
# Create an env and give it a bogus version number
|
||||
env = TradingEnvironment(load=noop_load)
|
||||
metadata = sa.MetaData(bind=env.engine)
|
||||
version_table = _version_table_schema(metadata)
|
||||
version_table.delete().execute()
|
||||
write_version_info(version_table, -2)
|
||||
check_version_info(version_table, -2)
|
||||
|
||||
# Assert that trying to build a finder with a bad db raises an error
|
||||
with self.assertRaises(AssetDBVersionError):
|
||||
AssetFinder(engine=env.engine)
|
||||
|
||||
# Change the version number of the db to the correct version
|
||||
version_table.delete().execute()
|
||||
write_version_info(version_table, ASSET_DB_VERSION)
|
||||
check_version_info(version_table, ASSET_DB_VERSION)
|
||||
|
||||
# Now that the versions match, this Finder should succeed
|
||||
AssetFinder(engine=env.engine)
|
||||
|
||||
@@ -37,9 +37,13 @@ from zipline.assets import (
|
||||
Asset, Equity, Future,
|
||||
)
|
||||
from zipline.assets.asset_writer import (
|
||||
check_version_info,
|
||||
split_delimited_symbol,
|
||||
asset_db_table_names,
|
||||
SQLITE_MAX_VARIABLE_NUMBER
|
||||
SQLITE_MAX_VARIABLE_NUMBER,
|
||||
)
|
||||
from zipline.assets.asset_db_schema import (
|
||||
ASSET_DB_VERSION
|
||||
)
|
||||
from zipline.utils.control_flow import invert
|
||||
|
||||
@@ -104,6 +108,9 @@ class AssetFinder(object):
|
||||
for table_name in asset_db_table_names:
|
||||
setattr(self, table_name, metadata.tables[table_name])
|
||||
|
||||
# Check the version info of the db for compatibility
|
||||
check_version_info(self.version_info, ASSET_DB_VERSION)
|
||||
|
||||
# Cache for lookup of assets by sid, the objects in the asset lookup
|
||||
# may be shared with the results from equity and future lookup caches.
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user