Skip to content

Commit

Permalink
Add force option to reflect_option and ensure that the table is in th…
Browse files Browse the repository at this point in the history
…e metadata cache
  • Loading branch information
albireox committed Jul 29, 2024
1 parent e614d8b commit 42f4cd3
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions python/sdssdb/peewee/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,19 @@ def reflect(self):
table_name = meta.table_name
schema = meta.schema

opts = getattr(meta, 'reflection_options', {})

if not database or not database.connected:
return

# Lists tables in the schema. This is a bit of a hack but
# faster than using database.table_exists because it's cached.
metadata = database._metadata
if schema not in metadata or len(metadata[schema]) == 0:
force = opts.get('force', False)
if (schema not in metadata
or len(metadata[schema]) == 0
or table_name not in metadata[schema]
or force):
database.get_fields(table_name, schema, cache=False)

schema_tables = metadata[schema].keys()
Expand All @@ -164,8 +170,7 @@ def reflect(self):
if not database.is_connection_usable():
raise peewee.DatabaseError('database not connected.')

if hasattr(meta, 'reflection_options'):
opts = meta.reflection_options
if opts:
skip_fks = opts.get('skip_foreign_keys', False)
use_peewee_reflection = opts.get('use_peewee_reflection', True)
else:
Expand Down

0 comments on commit 42f4cd3

Please sign in to comment.