Deleting a Layout that contains Blocks creates orphaned records in the CollectionVersionBlocks table

Permalink 0 0 Browser Info Environment
When you delete a Layout that contains other Blocks, it appears that orphaned rows remain in the CollectionVersionBlocks (CVB) table for every version of that page (collection) going forward.

I can reproduce the issue on a fresh installation of Concrete5 v8.2.1:

I created a new Empty page using the Blank page template. I added a Layout to the Main Area and then added a Content block inside the Layout. After publishing the page and querying the CVB table for the latest version of this page, I can see 2 rows as expected.

Next, I edit the page and Delete the Layout while it still contains the Content block. Now the page shows "Empty Main Area" and I published the changes. Querying the CVB table again for the latest version of my page, I still see 1 row and it has an arHandle value "Main : 50". Since this page no longer has any blocks that I can access in edit mode, I believe this is an issue.

Status: New

concrete5 Environment Information

# concrete5 Version
Core Version - 8.2.1
Version Installed - 8.2.1
Database Version - 20170802000000

# concrete5 Packages

# concrete5 Overrides

# concrete5 Cache Settings
Block Cache - On
Overrides Cache - On
Full Page Caching - Off
Full Page Cache Lifetime - Every 6 hours (default setting).

# Server Software

# Server API

# PHP Version

# PHP Extensions
apache2handler, bz2, calendar, Core, ctype, curl, date, dom, ereg, exif, fileinfo, filter, ftp, gd, gettext, hash, iconv, intl, json, ldap, libxml, mbstring, mcrypt, mhash, mssql, mysql, mysqli, mysqlnd, oci8, openssl, pcre, PDO, pdo_dblib, pdo_mysql, pdo_sqlite, Phar, posix, Reflection, session, shmop, SimpleXML, soap, sockets, SPL, sqlite3, standard, sysvmsg, sysvsem, sysvshm, tokenizer, wddx, xml, xmlreader, xmlwriter, xsl, zip, zlib

# PHP Settings
max_execution_time - 30
log_errors_max_len - 1024
max_file_uploads - 20
max_input_nesting_level - 64
max_input_time - 60
max_input_vars - 1000
memory_limit - 128M
post_max_size - 8M
sql.safe_mode - Off
upload_max_filesize - 2M
ldap.max_links - Unlimited
mssql.max_links - Unlimited
mssql.max_persistent - Unlimited
mssql.max_procs - Unlimited
mssql.textlimit - Server default
mysql.max_links - Unlimited
mysql.max_persistent - Unlimited
mysqli.max_links - Unlimited
mysqli.max_persistent - Unlimited
oci8.max_persistent - -1
pcre.backtrack_limit - 1000000
pcre.recursion_limit - 100000
session.cache_limiter - <i>no value</i>
session.gc_maxlifetime - 7200
soap.wsdl_cache_limit - 5

Browser User-Agent String

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36