|
18 | 18 |
|
19 | 19 | def _is_model_class(obj) -> bool: |
20 | 20 | """Is subclass of tortoise.Model, but not the base class""" |
21 | | - return isinstance(obj, type) and issubclass(obj, Model) and obj != Model |
| 21 | + return isinstance(obj, type) and issubclass(obj, Model) and obj != Model and not getattr(obj.Meta, 'abstract', False) |
22 | 22 |
|
23 | 23 |
|
24 | 24 | def _format_array_relationship( |
@@ -148,60 +148,58 @@ async def configure_hasura(config: DipDupConfig): |
148 | 148 | raise ConfigurationError('`hasura` config section missing') |
149 | 149 |
|
150 | 150 | _logger.info('Configuring Hasura') |
151 | | - |
152 | | - session = aiohttp.ClientSession() |
153 | 151 | url = config.hasura.url.rstrip("/") |
154 | 152 | hasura_metadata = await generate_hasura_metadata(config) |
155 | 153 |
|
156 | | - _logger.info('Waiting for Hasura instance to be healthy') |
157 | | - for _ in range(60): |
158 | | - with suppress(ClientConnectorError, ClientOSError): |
159 | | - async with aiohttp.ClientSession() as session: |
| 154 | + async with aiohttp.ClientSession() as session: |
| 155 | + _logger.info('Waiting for Hasura instance to be healthy') |
| 156 | + for _ in range(60): |
| 157 | + with suppress(ClientConnectorError, ClientOSError): |
160 | 158 | await session.get(f'{url}/healthz') |
161 | 159 | break |
162 | | - await asyncio.sleep(1) |
163 | | - else: |
164 | | - _logger.error('Hasura instance not responding for 60 seconds') |
165 | | - return |
166 | | - |
167 | | - headers = {} |
168 | | - if config.hasura.admin_secret: |
169 | | - headers['X-Hasura-Admin-Secret'] = config.hasura.admin_secret |
170 | | - |
171 | | - _logger.info('Fetching existing metadata') |
172 | | - existing_hasura_metadata = await http_request( |
173 | | - session, |
174 | | - 'post', |
175 | | - url=f'{url}/v1/query', |
176 | | - data=json.dumps( |
177 | | - { |
178 | | - "type": "export_metadata", |
179 | | - "args": hasura_metadata, |
180 | | - }, |
181 | | - ), |
182 | | - headers=headers, |
183 | | - ) |
184 | | - |
185 | | - _logger.info('Merging existing metadata') |
186 | | - hasura_metadata_tables = [table['table'] for table in hasura_metadata['tables']] |
187 | | - for table in existing_hasura_metadata['tables']: |
188 | | - if table['table'] not in hasura_metadata_tables: |
189 | | - hasura_metadata['tables'].append(table) |
190 | | - |
191 | | - _logger.info('Sending replace metadata request') |
192 | | - result = await http_request( |
193 | | - session, |
194 | | - 'post', |
195 | | - url=f'{url}/v1/query', |
196 | | - data=json.dumps( |
197 | | - { |
198 | | - "type": "replace_metadata", |
199 | | - "args": hasura_metadata, |
200 | | - }, |
201 | | - ), |
202 | | - headers=headers, |
203 | | - ) |
204 | | - if not result.get('message') == 'success': |
205 | | - _logger.error('Can\'t configure Hasura instance: %s', result) |
| 160 | + await asyncio.sleep(1) |
| 161 | + else: |
| 162 | + _logger.error('Hasura instance not responding for 60 seconds') |
| 163 | + return |
| 164 | + |
| 165 | + headers = {} |
| 166 | + if config.hasura.admin_secret: |
| 167 | + headers['X-Hasura-Admin-Secret'] = config.hasura.admin_secret |
| 168 | + |
| 169 | + _logger.info('Fetching existing metadata') |
| 170 | + existing_hasura_metadata = await http_request( |
| 171 | + session, |
| 172 | + 'post', |
| 173 | + url=f'{url}/v1/query', |
| 174 | + data=json.dumps( |
| 175 | + { |
| 176 | + "type": "export_metadata", |
| 177 | + "args": hasura_metadata, |
| 178 | + }, |
| 179 | + ), |
| 180 | + headers=headers, |
| 181 | + ) |
206 | 182 |
|
207 | | - await session.close() |
| 183 | + _logger.info('Merging existing metadata') |
| 184 | + hasura_metadata_tables = [table['table'] for table in hasura_metadata['tables']] |
| 185 | + for table in existing_hasura_metadata['tables']: |
| 186 | + if table['table'] not in hasura_metadata_tables: |
| 187 | + hasura_metadata['tables'].append(table) |
| 188 | + |
| 189 | + _logger.info('Sending replace metadata request') |
| 190 | + result = await http_request( |
| 191 | + session, |
| 192 | + 'post', |
| 193 | + url=f'{url}/v1/query', |
| 194 | + data=json.dumps( |
| 195 | + { |
| 196 | + "type": "replace_metadata", |
| 197 | + "args": hasura_metadata, |
| 198 | + }, |
| 199 | + ), |
| 200 | + headers=headers, |
| 201 | + ) |
| 202 | + if not result.get('message') == 'success': |
| 203 | + _logger.error('Can\'t configure Hasura instance: %s', result) |
| 204 | + else: |
| 205 | + _logger.info('Hasura instance has been configured') |
0 commit comments