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

Add check for missing year in models Release and Master #144

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions discogs_client/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,8 @@ class Release(PrimaryAPIObject):
def __init__(self, client, dict_):
super(Release, self).__init__(client, dict_)
self.data['resource_url'] = '{0}/releases/{1}'.format(client._base_url, dict_['id'])
if not 'year' in dict_:
dict_['year'] = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, sorry for the delay in responding, I'm travelling and try to stay offline as much as I can ;-) Also excuse any sloppy formatting, I try to do my best while editing on mobile...

Anyway, interesting, and yes it's a quickfix but I'm wondering how we could make it a fix for potentially all fields that could be missing.

I'm probably just thinking out loud and havent thought all this through thoroughly enough, but:

We are defining year as a SimpleField here:

year = SimpleField() #:

Why wouldnt it be possible to fall back to None here already?

class SimpleField(Field):

descriptor class:

def __get__(self, instance, owner):

the ObjectDescriptor class does have some kind of fallback to None, we could try to do something similar in the SimpleDescriptor:

if self.optional and not response_dict:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesnt year default to 0 if no year is specified so there should always be a value


@property
def master(self):
Expand Down Expand Up @@ -606,6 +608,8 @@ class Master(PrimaryAPIObject):
def __init__(self, client, dict_):
super(Master, self).__init__(client, dict_)
self.data['resource_url'] = '{0}/masters/{1}'.format(client._base_url, dict_['id'])
if not 'year' in dict_:
dict_['year'] = None

def __repr__(self):
return '<Master {0!r} {1!r}>'.format(self.id, self.title)
Expand Down