Remove Collection Field data from Entry when Field is deleted?

I noticed that the api is returning data from deleted fields. In the example below, I created a field called DELETE_TEST_DATA, updated it, then deleted the field. I’m curious if there is a way to remove the data once the field is removed. This could be a security issue.

Edit: This also happens if you rename a field. Is there a way to prune the collections to only store the active fields?

{
	"fields": {
		"title": {
			"name": "title",
			"type": "text",
			"localize": false,
			"options": {
				"slug": true
			}
		},
		"folder": {
			"name": "folder",
			"type": "text",
			"localize": false,
			"options": {
				"pattern": "^([a-zA-Z0-9-_]+)$"
			}
		}
	},
	"entries": [
		{
			"title": "One",
			"folder": "one",
			"title_slug": "one",
			"_mby": "5fcaee0337346580b20001a7",
			"_by": "5fcaee0337346580b20001a7",
			"_o": 1,
			"_modified": 1609723892,
			"_created": 1609723525,
			"_id": "5ff26e85633533429b0001a9",
			"DELETE_TEST_DATA": "THIS SHOULD NOT BE HERE!"
		}
	],
	"total": 1
}

It’s not a bug - it’s a feature, but I see the problem.

Keeping only active fields is probably a bad idea, because there are a lot of hidden fields, e. g.:

  • meta info _created, _modified etc.
  • localized fields with language code suffixes title_de
  • auto generated slugs title_slug
  • some addons create hidden meta fields, e. g. UniqueSlugs…

But there is a cli command to fix that behaviour.

cd /path/to/cockpit
php ./cp collection/removefield --collection <collection name> --field <field name>
cd /path/to/cockpit
php ./cp collection/renamefield --collection <collection name> --field <field name> --newfield <new field name>

See: https://github.com/agentejo/cockpit/tree/next/modules/Collections/cli/collection

Both cli commands change the contents in the database, but they don’t change the field definitions in your collection settings. So performing the simple step of renaming/deleting a field is a bit complicated, but the tools to handle visible and hidden fields are available.

Yes i noticed this too. It drives me crazy. I have no idea why this was left in. If bloats the json as well. If you delete a field you clearly don’t want it’s data

1 Like