
from google.appengine.ext import ndb

class Publisher(ndb.Model):
  '''Publisher object in datastore.

  Holds publisher data.
  '''
  identifier = ndb.IntegerProperty()
  name = ndb.StringProperty()
  image = ndb.StringProperty()

def fetch_or_store(identifier, publisher):
  publisher_key = Publisher.query(Publisher.identifier==identifier).get()
  if not publisher_key:
    publisher_key = Publisher(identifier=publisher.id, name=publisher.name,
                              image=publisher.image['tiny_url'])
    publisher_key.put()
  return publisher_key


from google.appengine.ext import ndb

class Publisher(ndb.Model):
  '''Publisher object in datastore.

  Holds publisher data.
  '''
  identifier = ndb.IntegerProperty()
  name = ndb.StringProperty()
  image = ndb.StringProperty()

def fetch_or_store(identifier, publisher):
  publisher_key = Publisher.query(Publisher.identifier==identifier).get()
  if not publisher_key:
    publisher_key = Publisher(identifier=publisher.id, name=publisher.name)
    if publisher.image:
      publisher_key.image=publisher.image.get('tiny_url')
    publisher_key.put()
  return publisher_key

Handle null image attribute on publisher
Handle null image attribute on publisher

  
  from google.appengine.ext import ndb
  
  class Publisher(ndb.Model):
    '''Publisher object in datastore.
  
    Holds publisher data.
    '''
    identifier = ndb.IntegerProperty()
    name = ndb.StringProperty()
    image = ndb.StringProperty()
  
  def fetch_or_store(identifier, publisher):
    publisher_key = Publisher.query(Publisher.identifier==identifier).get()
    if not publisher_key:
-     publisher_key = Publisher(identifier=publisher.id, name=publisher.name,
+     publisher_key = Publisher(identifier=publisher.id, name=publisher.name)
-                               image=publisher.image['tiny_url'])
+     if publisher.image:
+       publisher_key.image=publisher.image.get('tiny_url')
      publisher_key.put()
    return publisher_key
  
Handle null image attribute on publisher
## Code Before:

from google.appengine.ext import ndb

class Publisher(ndb.Model):
  '''Publisher object in datastore.

  Holds publisher data.
  '''
  identifier = ndb.IntegerProperty()
  name = ndb.StringProperty()
  image = ndb.StringProperty()

def fetch_or_store(identifier, publisher):
  publisher_key = Publisher.query(Publisher.identifier==identifier).get()
  if not publisher_key:
    publisher_key = Publisher(identifier=publisher.id, name=publisher.name,
                              image=publisher.image['tiny_url'])
    publisher_key.put()
  return publisher_key

## Instruction:
Handle null image attribute on publisher
## Code After:

from google.appengine.ext import ndb

class Publisher(ndb.Model):
  '''Publisher object in datastore.

  Holds publisher data.
  '''
  identifier = ndb.IntegerProperty()
  name = ndb.StringProperty()
  image = ndb.StringProperty()

def fetch_or_store(identifier, publisher):
  publisher_key = Publisher.query(Publisher.identifier==identifier).get()
  if not publisher_key:
    publisher_key = Publisher(identifier=publisher.id, name=publisher.name)
    if publisher.image:
      publisher_key.image=publisher.image.get('tiny_url')
    publisher_key.put()
  return publisher_key
