# Buggy code
def write(self, path=None, tags=None):
    """Write the item's metadata to a media file.

    All fields in `_media_fields` are written to disk according to
    the values on this object.

    `path` is the path of the mediafile to wirte the data to. It
    defaults to the item's path.

    `tags` is a dictionary of additional metadata the should be
    written to the file.

    Can raise either a `ReadError` or a `WriteError`.
    """
    if path is None:
        path = self.path
    else:
        path = normpath(path)

    item_tags = dict(self)
    if tags is not None:
        item_tags.update(tags)
    plugins.send("write", item=self, path=path, tags=item_tags)

    try:
        mediafile = MediaFile(syspath(path), id3v23=beets.config["id3v23"].get(bool))
    except (OSError, IOError, UnreadableFileError) as exc:
        raise ReadError(self.path, exc)

    mediafile.update(item_tags)
    try:
        mediafile.save()
    except (OSError, IOError, MutagenError) as exc:
        raise WriteError(self.path, exc)

    # The file has a new mtime.
    if path == self.path:
        self.mtime = self.current_mtime()
    plugins.send("after_write", item=self, path=path)


# Traceback (AttributeError)
user configuration: /home/user/.config/beets/config.yaml
data directory: /home/user/.config/beets
plugin paths: 
Sending event: pluginload
library database: /home/user/.beets-data/musiclibrary.blb
library directory: /home/user/Music
Sending event: library_opened
Modifying 13 items.
10 Years - The Autumn Effect - Fault Line
  date: 2005-08-16
10 Years - The Autumn Effect - The Recipe
  date: 2005-08-16
10 Years - The Autumn Effect - Cast it Out
  date: 2005-08-16
10 Years - The Autumn Effect - Wasteland
  date: 2005-08-16
10 Years - The Autumn Effect - Seasons to Cycles
  date: 2005-08-16
10 Years - The Autumn Effect - Half Life
  date: 2005-08-16
10 Years - The Autumn Effect - Through the Iris
  date: 2005-08-16
10 Years - The Autumn Effect - Empires
  date: 2005-08-16
10 Years - The Autumn Effect - Prey
  date: 2005-08-16
10 Years - The Autumn Effect - Insects
  date: 2005-08-16
10 Years - The Autumn Effect - Paralyzing Kings
  date: 2005-08-16
10 Years - The Autumn Effect - The Autumn Effect / Slowly Falling Awake
  date: 2005-08-16
Really modify, move and write tags (Y/n)? y
moving object /home/user/Music/10 Years/The Autumn Effect/11 Insects.flac
Sending event: before_item_moved
Sending event: item_moved
Sending event: database_change
Sending event: database_change
Sending event: write
Traceback (most recent call last):
  File "/usr/bin/beet", line 9, in <module>
    load_entry_point('beets==1.3.11', 'console_scripts', 'beet')()
  File "/usr/lib/python2.7/site-packages/beets/ui/__init__.py", line 1081, in main
    _raw_main(args)
  File "/usr/lib/python2.7/site-packages/beets/ui/__init__.py", line 1071, in _raw_main
    subcommand.func(lib, suboptions, subargs)
  File "/usr/lib/python2.7/site-packages/beets/ui/commands.py", line 1328, in modify_func
    not opts.yes)
  File "/usr/lib/python2.7/site-packages/beets/ui/commands.py", line 1299, in modify_items
    obj.try_sync(write)
  File "/usr/lib/python2.7/site-packages/beets/library.py", line 610, in try_sync
    self.try_write(path=write)
  File "/usr/lib/python2.7/site-packages/beets/library.py", line 591, in try_write
    self.write(path, tags)
  File "/usr/lib/python2.7/site-packages/beets/library.py", line 573, in write
    mediafile.update(item_tags)
  File "/usr/lib/python2.7/site-packages/beets/mediafile.py", line 1490, in update
    setattr(self, field, dict[field])
  File "/usr/lib/python2.7/site-packages/beets/mediafile.py", line 1158, in __set__
    self._set_date_tuple(mediafile, date.year, date.month, date.day)
AttributeError: 'unicode' object has no attribute 'year'


# Fixed code
def write(self, path=None, tags=None):
    """Write the item's metadata to a media file.

    All fields in `_media_fields` are written to disk according to
    the values on this object.

    `path` is the path of the mediafile to wirte the data to. It
    defaults to the item's path.

    `tags` is a dictionary of additional metadata the should be
    written to the file. (These tags need not be in `_media_fields`.)

    Can raise either a `ReadError` or a `WriteError`.
    """
    if path is None:
        path = self.path
    else:
        path = normpath(path)

    # Get the data to write to the file.
    item_tags = dict(self)
    item_tags = {
        k: v for k, v in item_tags.items() if k in self._media_fields
    }  # Only write media fields.
    if tags is not None:
        item_tags.update(tags)
    plugins.send("write", item=self, path=path, tags=item_tags)

    # Open the file.
    try:
        mediafile = MediaFile(syspath(path), id3v23=beets.config["id3v23"].get(bool))
    except (OSError, IOError, UnreadableFileError) as exc:
        raise ReadError(self.path, exc)

    # Write the tags to the file.
    mediafile.update(item_tags)
    try:
        mediafile.save()
    except (OSError, IOError, MutagenError) as exc:
        raise WriteError(self.path, exc)

    # The file has a new mtime.
    if path == self.path:
        self.mtime = self.current_mtime()
    plugins.send("after_write", item=self, path=path)