# Plugins: how to check for existence of a field in an item

**URL:** <https://discourse.beets.io/t/plugins-how-to-check-for-existence-of-a-field-in-an-item/1253>\
**Category:** Help\
**Created:** [May 6, 2020, 2:11am UTC](https://discourse.beets.io/t/plugins-how-to-check-for-existence-of-a-field-in-an-item/1253 "2020-05-06T02:11:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![phirestalker](https://avatars.discourse-cdn.com/v4/letter/p/d6d6ee/32.png) [@phirestalker](https://discourse.beets.io/u/phirestalker)\
**Post date:** [May 6, 2020, 2:11am UTC](https://discourse.beets.io/t/plugins-how-to-check-for-existence-of-a-field-in-an-item/1253/1 "2020-05-06T02:11:11Z")

</div>

I am modifying a plugin and I need to check for the existence of a custom tag that the plugin creates. This way I can skip tracks that have already been processed. The plugin grabs an “item” from lib.items(query). In the item it creates a tag called recording\_year. I have tried:

> if u’recording\_year’ in item:  
> and  
> if u’recording\_year’ in item.keys():

Both options do not skip already processed files. What is the proper method to check for the existence of the custom field?

---

<div class="post-metadata">

**Author:** ![adrian](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/adrian/32/4_2.png) [@adrian](https://discourse.beets.io/u/adrian)\
**Post date:** [May 6, 2020, 11:36am UTC](https://discourse.beets.io/t/plugins-how-to-check-for-existence-of-a-field-in-an-item/1253/2 "2020-05-06T11:36:48Z")

</div>

Huh, that should do it (even the first, simpler version). Can you maybe try printing out `list(item.keys())` or perhaps even `item.get('recording_year')` to confirm that those items don’t actually have the field?

---

<div class="post-metadata">

**Author:** ![phirestalker](https://avatars.discourse-cdn.com/v4/letter/p/d6d6ee/32.png) [@phirestalker](https://discourse.beets.io/u/phirestalker)\
**Post date:** [May 6, 2020, 2:18pm UTC](https://discourse.beets.io/t/plugins-how-to-check-for-existence-of-a-field-in-an-item/1253/3 "2020-05-06T14:18:17Z")

</div>

You’re right, the field isn’t populated. I can open the file in a tag editor and see the tag, but according to beets it isn’t there. The plugin is here: [https://github.com/phirestalker/beets-recordingdate](https://github.com/phirestalker/beets-recordingdate) or at least my copy of it. So if it is sucessfully adding the field to the file, why isn’t beets seeing the field?

EDIT: I did a beet update and now it is working as it should.

So, the question then becomes, how should the plugin force an update of each item in the beets database?

---

<div class="post-metadata">

**Author:** ![phirestalker](https://avatars.discourse-cdn.com/v4/letter/p/d6d6ee/32.png) [@phirestalker](https://discourse.beets.io/u/phirestalker)\
**Post date:** [May 6, 2020, 6:06pm UTC](https://discourse.beets.io/t/plugins-how-to-check-for-existence-of-a-field-in-an-item/1253/4 "2020-05-06T18:06:43Z")

</div>

OK. I added item.store() after the item.write() and that seems to be updating that track in the database. Can you do me a huge favor and look over the plugin?

For some reason it seems to be hitting the internet even though as far as I can tell the code to skip tracks comes before the code to query the musicbrainz server.
