Entity.columns class property replaced by Entity.get_columns method.

Again, Python < 3.9 doesn't like the combination of `@property` +
`@classmethod`.
This commit is contained in:
Fabio Manganiello 2023-08-18 17:20:53 +02:00
parent a9cdff900e
commit 2cab836bdf
Signed by: blacklight
GPG key ID: D90FBA7F76362774
3 changed files with 16 additions and 10 deletions

View file

@ -117,9 +117,8 @@ if 'entity' not in Base.metadata:
'polymorphic_on': type, 'polymorphic_on': type,
} }
@classmethod # type: ignore @classmethod
@property def get_columns(cls) -> Tuple[ColumnProperty, ...]:
def columns(cls) -> Tuple[ColumnProperty, ...]:
inspector = schema_inspect(cls) inspector = schema_inspect(cls)
return tuple(inspector.mapper.column_attrs) return tuple(inspector.mapper.column_attrs)
@ -146,7 +145,7 @@ if 'entity' not in Base.metadata:
return self.__class__( return self.__class__(
**dict( **dict(
key_value_pair(col) # type: ignore key_value_pair(col) # type: ignore
for col in self.columns for col in self.get_columns()
if key_value_pair(col) is not None if key_value_pair(col) is not None
), ),
children=[child.copy() for child in self.children], children=[child.copy() for child in self.children],
@ -213,7 +212,7 @@ if 'entity' not in Base.metadata:
return { return {
**dict( **dict(
self._column_to_pair(col) self._column_to_pair(col)
for col in self.columns for col in self.get_columns()
if self._column_to_pair(col) if self._column_to_pair(col)
), ),
'children_ids': self.children_ids, 'children_ids': self.children_ids,
@ -241,7 +240,7 @@ if 'entity' not in Base.metadata:
""" """
Serializes the new value before assigning it to an attribute. Serializes the new value before assigning it to an attribute.
""" """
matching_columns = [c for c in self.columns if c.expression.name == key] # type: ignore matching_columns = [c for c in self.get_columns() if c.expression.name == key] # type: ignore
if ( if (
matching_columns matching_columns

View file

@ -176,7 +176,7 @@ class EntitiesMerger:
""" """
Merge two versions of an entity column by column. Merge two versions of an entity column by column.
""" """
columns = [col.key for col in entity.columns] columns = [col.key for col in entity.get_columns()]
for col in columns: for col in columns:
if col == 'meta': if col == 'meta':
existing_entity.meta = { # type: ignore existing_entity.meta = { # type: ignore
@ -189,7 +189,9 @@ class EntitiesMerger:
except ObjectDeletedError as e: except ObjectDeletedError as e:
logger.warning( logger.warning(
'Could not set %s on entity <%s>: %s', 'Could not set %s on entity <%s>: %s',
col, existing_entity.entity_key, e col,
existing_entity.entity_key,
e,
) )
# Recursive call to merge the columns of the children too # Recursive call to merge the columns of the children too

View file

@ -44,6 +44,8 @@ class RssPlugin(RunnablePlugin):
+ 'Chrome/62.0.3202.94 Safari/537.36' + 'Chrome/62.0.3202.94 Safari/537.36'
) )
timeout = 20
def __init__( def __init__(
self, self,
subscriptions: Optional[Collection[str]] = None, subscriptions: Optional[Collection[str]] = None,
@ -117,7 +119,9 @@ class RssPlugin(RunnablePlugin):
import feedparser import feedparser
feed = feedparser.parse( feed = feedparser.parse(
requests.get(url, headers={'User-Agent': self.user_agent}, timeout=20).text, requests.get(
url, headers={'User-Agent': self.user_agent}, timeout=self.timeout
).text,
) )
return RssFeedEntrySchema().dump( return RssFeedEntrySchema().dump(
sorted( sorted(
@ -200,6 +204,7 @@ class RssPlugin(RunnablePlugin):
headers={ headers={
'User-Agent': self.user_agent, 'User-Agent': self.user_agent,
}, },
timeout=self.timeout,
).text ).text
except Exception as e: except Exception as e:
self.logger.warning('Could not retrieve subscription %s: %s', url, e) self.logger.warning('Could not retrieve subscription %s: %s', url, e)
@ -365,7 +370,7 @@ class RssPlugin(RunnablePlugin):
url = response['url'] url = response['url']
error = response.get('error') error = response.get('error')
if error: if error:
self.logger.error(f'Could not parse feed {url}: {error}') self.logger.error('Could not parse feed %s: %s', url, error)
responses[url] = error responses[url] = error
else: else:
responses[url] = response['content'] responses[url] = response['content']