Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/95 provider super #96

Merged
merged 2 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion skosprovider_sqlalchemy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ class Collection(Thing):
members = relationship(
'Thing',
secondary=collection_concept,
backref=backref('member_of', collection_class=set),
backref=backref('member_of', collection_class=set, cascade_backrefs=False),
primaryjoin='Thing.id==collection_concept.c.collection_id',
secondaryjoin='Thing.id==collection_concept.c.concept_id',
collection_class=set
Expand Down
28 changes: 16 additions & 12 deletions skosprovider_sqlalchemy/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,40 +57,44 @@ def __init__(self, metadata, session, **kwargs):
:param :class:`sqlachemy.orm.session.Session` session: The database
session. This can also be a callable that returns a Session.
'''
if 'subject' not in metadata:
metadata['subject'] = []
self.metadata = metadata
if 'uri_generator' in kwargs:
self.uri_generator = kwargs.get('uri_generator')
else:
self.uri_generator = DefaultUrnGenerator(self.metadata.get('id'))
super().__init__(
metadata,
allowed_instance_scopes=['single', 'threaded_thread'],
concept_scheme=None,
**kwargs
)
try:
self.session = session()
except TypeError:
self.session = session

try:
self.conceptscheme_id = int(metadata.get(
'conceptscheme_id', metadata.get('id')
))
except ValueError:
self.conceptscheme_id = int(
metadata.get('conceptscheme_id', metadata.get('id'))
)
except (ValueError, TypeError):
raise ValueError(
'Please provide a valid integer for the conceptscheme_id.'
)

if 'expand_strategy' in kwargs:
if kwargs['expand_strategy'] in ['recurse', 'visit']:
self.expand_strategy = kwargs['expand_strategy']
else:
raise ValueError(
'Unknown expand strategy.'
)
self.allowed_instance_scopes = ['single', 'threaded_thread']

@property
def concept_scheme(self):
if self._conceptscheme is None:
self._conceptscheme = self._get_concept_scheme()
return self._conceptscheme

@concept_scheme.setter
def concept_scheme(self, _):
"""Ignore the super class setting a concept_scheme."""

def _get_concept_scheme(self):
'''
Find a :class:`skosprovider.skos.ConceptScheme` for this provider.
Expand Down