AssertionError in export_mapbox, caused by a corrupted merged location
sentry-io opened this issue · comments
Sentry Issue: VIAL-BR
AssertionError:
(3 additional frame(s) were not displayed)
...
File "api/utils.py", line 93, in replacement_view_function
response = view_fn(request, *args, **kwargs)
File "django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "api/export_mapbox.py", line 189, in export_mapbox
_mapbox_geojson(location, expansion), option=orjson.OPT_APPEND_NEWLINE
File "api/export_mapbox.py", line 82, in _mapbox_geojson
"appointment_details": report.full_appointment_details(location),
File "core/models.py", line 1127, in full_appointment_details
assert location.id == self.location_id
Discord: https://discord.com/channels/799147121357881364/813861006718926848/858057432592941136
Ugaso tracked it to this report https://vial.calltheshots.us/admin/core/report/35224/change/ on this location: https://vial.calltheshots.us/admin/core/location/8234/history/
Here's the method with the failing assertion:
Lines 1125 to 1146 in cdaaab0
And here's where it's being called with a location that doesn't correctly match:
vial/vaccinate/core/exporter/__init__.py
Lines 248 to 271 in cdaaab0
So it looks like latest = location.dn_latest_non_skip_report
is somehow returning a report that points to a different location.
select location.id, report.location_id
from location join report on location.dn_latest_non_skip_report_id = report.id
where location.id != report.location_id
This query should never return any results... but it's returning 318!
Here's the full list of affected locations:
- https://vial.calltheshots.us/location/rec7nXQcPKA20TDyd
- https://vial.calltheshots.us/location/lwpgt
- https://vial.calltheshots.us/location/lwxxq
- https://vial.calltheshots.us/location/recPQy9RZdzi7EkSs
- https://vial.calltheshots.us/location/lcdkxy
- https://vial.calltheshots.us/location/lcdkyc
- https://vial.calltheshots.us/location/recYslxGVYCqX25mE
- https://vial.calltheshots.us/location/lcdfqp
- https://vial.calltheshots.us/location/lcddcq
- https://vial.calltheshots.us/location/lddkt
- https://vial.calltheshots.us/location/lccwpy
- https://vial.calltheshots.us/location/lcddrw
- https://vial.calltheshots.us/location/lybfz
- https://vial.calltheshots.us/location/lcdpcr
- https://vial.calltheshots.us/location/recdbfPGb5GLcQvAH
- https://vial.calltheshots.us/location/lqxxd
- https://vial.calltheshots.us/location/lcdpdq
- https://vial.calltheshots.us/location/lwqtx
- https://vial.calltheshots.us/location/lcdrrq
- https://vial.calltheshots.us/location/lrzbb
- https://vial.calltheshots.us/location/lddkr
- https://vial.calltheshots.us/location/ldczg
- https://vial.calltheshots.us/location/lcyqr
- https://vial.calltheshots.us/location/recjwNcfea0fRH9lM
- https://vial.calltheshots.us/location/lwwmx
- https://vial.calltheshots.us/location/lxbqp
- https://vial.calltheshots.us/location/lfczh
- https://vial.calltheshots.us/location/lywtb
- https://vial.calltheshots.us/location/lczgr
- https://vial.calltheshots.us/location/reckQ8qk9NhK07Gth
- https://vial.calltheshots.us/location/lcdqtt
- https://vial.calltheshots.us/location/lccdrm
- https://vial.calltheshots.us/location/lccfzy
- https://vial.calltheshots.us/location/ldkgg
- https://vial.calltheshots.us/location/ldkkp
- https://vial.calltheshots.us/location/rec4cX5FO2bgif0rI
- https://vial.calltheshots.us/location/lzyxb
- https://vial.calltheshots.us/location/rec7nfRGnk5JcnmQR
- https://vial.calltheshots.us/location/recWqoMmBXBUDnS4z
- https://vial.calltheshots.us/location/lrbqf
- https://vial.calltheshots.us/location/lccwyr
- https://vial.calltheshots.us/location/recf4jgpkwmch6dpO
- https://vial.calltheshots.us/location/recs6GFdnQ511yRBR
- https://vial.calltheshots.us/location/ldbbm
- https://vial.calltheshots.us/location/recXiIhBWd4VzZOwV
- https://vial.calltheshots.us/location/lrzfm
- https://vial.calltheshots.us/location/recJ3t8OpeN97keju
- https://vial.calltheshots.us/location/recZUalyiVK3yVrAs
- https://vial.calltheshots.us/location/recr7RmSOOelWxQb5
- https://vial.calltheshots.us/location/recSNFTlLMEkncecP
- https://vial.calltheshots.us/location/recUpTSDnm2pxNGfR
- https://vial.calltheshots.us/location/ldfdf
- https://vial.calltheshots.us/location/ldftk
- https://vial.calltheshots.us/location/rec62E6XchlhO6Dk9
- https://vial.calltheshots.us/location/lcyxw
- https://vial.calltheshots.us/location/ldccg
- https://vial.calltheshots.us/location/recX4hHB3ApyzQQNx
- https://vial.calltheshots.us/location/rec5Sg0lmi9MRs8to
- https://vial.calltheshots.us/location/recWst6UD3qgtcqvf
- https://vial.calltheshots.us/location/recm83qKAQGeusEsA
- https://vial.calltheshots.us/location/ldcyp
- https://vial.calltheshots.us/location/recnnRoeXbqaZ4jsH
- https://vial.calltheshots.us/location/recmWyHieViG2mSJd
- https://vial.calltheshots.us/location/recc5wZEqum38XaCX
- https://vial.calltheshots.us/location/lczff
- https://vial.calltheshots.us/location/recS42DAJpLVmwNxe
- https://vial.calltheshots.us/location/recstXNwHbSC73xOi
- https://vial.calltheshots.us/location/recQ21IHsPopvPNv7
- https://vial.calltheshots.us/location/recYexkMhSXkrzUWL
- https://vial.calltheshots.us/location/lczzy
- https://vial.calltheshots.us/location/ldfdz
- https://vial.calltheshots.us/location/recfKD1iSGYJTC1c4
- https://vial.calltheshots.us/location/recF8rMsbDwBciEy4
- https://vial.calltheshots.us/location/ldfdg
- https://vial.calltheshots.us/location/recomPlIF6rRJH0dp
- https://vial.calltheshots.us/location/lcctqq
- https://vial.calltheshots.us/location/recKSau9zVKZ8IQT6
- https://vial.calltheshots.us/location/reczRi12TqLXjm88o
- https://vial.calltheshots.us/location/ldbyr
- https://vial.calltheshots.us/location/recjao9gpjjFURsTb
- https://vial.calltheshots.us/location/ldfwq
- https://vial.calltheshots.us/location/recgXT02Do8EplxQw
- https://vial.calltheshots.us/location/lfctz
- https://vial.calltheshots.us/location/recLHEstEXXTUf2T0
- https://vial.calltheshots.us/location/recBTiEC4koQqFQD9
- https://vial.calltheshots.us/location/ldczx
- https://vial.calltheshots.us/location/recgHEpysqJ41TEU4
- https://vial.calltheshots.us/location/ldcym
- https://vial.calltheshots.us/location/recN56u07iasHVglN
- https://vial.calltheshots.us/location/recvf9dTRHgHZiHkR
- https://vial.calltheshots.us/location/lcdmtk
- https://vial.calltheshots.us/location/lccrhd
- https://vial.calltheshots.us/location/lcdbdt
- https://vial.calltheshots.us/location/rec4w3frZLUW0pW7o
- https://vial.calltheshots.us/location/lcdfqd
- https://vial.calltheshots.us/location/recX0pSbx1qtH6Quf
- https://vial.calltheshots.us/location/lcccyf
- https://vial.calltheshots.us/location/lcdgkr
- https://vial.calltheshots.us/location/lcddpz
- https://vial.calltheshots.us/location/lcyrw
- https://vial.calltheshots.us/location/lcddrt
- https://vial.calltheshots.us/location/lcdbgp
- https://vial.calltheshots.us/location/lcdpdf
- https://vial.calltheshots.us/location/lcdpdh
- https://vial.calltheshots.us/location/lqycp
- https://vial.calltheshots.us/location/lcdpdm
- https://vial.calltheshots.us/location/lryzd
- https://vial.calltheshots.us/location/ldbmm
- https://vial.calltheshots.us/location/recW0Ll72TDayAEqs
- https://vial.calltheshots.us/location/lcdrqx
- https://vial.calltheshots.us/location/ltbff
- https://vial.calltheshots.us/location/ltbfg
- https://vial.calltheshots.us/location/recRsS2S3bsCyQcTZ
- https://vial.calltheshots.us/location/ldkqh
- https://vial.calltheshots.us/location/lcdcww
- https://vial.calltheshots.us/location/ldczm
- https://vial.calltheshots.us/location/lcyyw
- https://vial.calltheshots.us/location/lcbycc
- https://vial.calltheshots.us/location/lttmw
- https://vial.calltheshots.us/location/lytgk
- https://vial.calltheshots.us/location/lzrpz
- https://vial.calltheshots.us/location/lyzpt
- https://vial.calltheshots.us/location/lqykb
- https://vial.calltheshots.us/location/recDwqelPMV9LR1Q0
- https://vial.calltheshots.us/location/reccJJQy2pdNtSuIQ
- https://vial.calltheshots.us/location/recE3vjErOAx6ROGA
- https://vial.calltheshots.us/location/recxPS58ghEY7IfNw
- https://vial.calltheshots.us/location/ltdqp
- https://vial.calltheshots.us/location/recTzWO20IAjnrcdS
- https://vial.calltheshots.us/location/recAuviAO4C5ukkcb
- https://vial.calltheshots.us/location/lzmqh
- https://vial.calltheshots.us/location/recX1jBoeQ2WtcmpJ
- https://vial.calltheshots.us/location/recQcT6AcKpxx4gq2
- https://vial.calltheshots.us/location/recQY7j3pexObXbxv
- https://vial.calltheshots.us/location/lccwgx
- https://vial.calltheshots.us/location/recFmWyrT4MPkR4iX
- https://vial.calltheshots.us/location/recsxtLUbSipVKmZM
- https://vial.calltheshots.us/location/recRCoDXkbIqFPtS6
- https://vial.calltheshots.us/location/recy5bLKKuXE5ZWYI
- https://vial.calltheshots.us/location/recLkAn98Er2wDvDF
- https://vial.calltheshots.us/location/lddmb
- https://vial.calltheshots.us/location/recbpeLJzvRuak1q2
- https://vial.calltheshots.us/location/recNUwfgdagkPMa6l
- https://vial.calltheshots.us/location/recGmUgfBKD3ncDNO
- https://vial.calltheshots.us/location/recnUMWw2sYsowv3B
- https://vial.calltheshots.us/location/rec2DVhVYMkUUtor9
- https://vial.calltheshots.us/location/recAfWjXbzFbXiRqX
- https://vial.calltheshots.us/location/lddxh
- https://vial.calltheshots.us/location/recEeAqIuRMoK1mcd
- https://vial.calltheshots.us/location/ldbrq
- https://vial.calltheshots.us/location/recqwx40quChiJVTT
- https://vial.calltheshots.us/location/reccyhil6zSWeg5xf
- https://vial.calltheshots.us/location/lddwq
- https://vial.calltheshots.us/location/recrg1YKLQSueW8Sr
- https://vial.calltheshots.us/location/reca2FWqS55SzmLTf
- https://vial.calltheshots.us/location/recUnWhK8aVYFwNvL
- https://vial.calltheshots.us/location/recdIqppigJ6LwG0J
- https://vial.calltheshots.us/location/recO1MbKnClC6wfNf
- https://vial.calltheshots.us/location/rec9r94SHNCIEEFmT
- https://vial.calltheshots.us/location/recdw4RYFgMIYilO4
- https://vial.calltheshots.us/location/ldbtt
- https://vial.calltheshots.us/location/rec6g8vdLUalVeJ9W
- https://vial.calltheshots.us/location/recgIE1lJdfWU55Jd
- https://vial.calltheshots.us/location/recsj9dehKy0kzOFI
- https://vial.calltheshots.us/location/recpjF6SyYElx2DDR
- https://vial.calltheshots.us/location/ldfxt
- https://vial.calltheshots.us/location/reckyZNdgUjfH9zzs
- https://vial.calltheshots.us/location/recPYsQ64G5kNPp3R
- https://vial.calltheshots.us/location/lrzkw
- https://vial.calltheshots.us/location/lcdfkr
- https://vial.calltheshots.us/location/lcdcwt
- https://vial.calltheshots.us/location/lcdfqb
- https://vial.calltheshots.us/location/lcddbr
- https://vial.calltheshots.us/location/recPtfX1nCYvlE2ff
- https://vial.calltheshots.us/location/lzbth
- https://vial.calltheshots.us/location/lcctmp
- https://vial.calltheshots.us/location/rec0qfGnr75nbBKwn
- https://vial.calltheshots.us/location/lcddrr
- https://vial.calltheshots.us/location/recFd5D8qArzD1yfT
- https://vial.calltheshots.us/location/lcccwg
- https://vial.calltheshots.us/location/recgX7k94wXMrHGfg
- https://vial.calltheshots.us/location/lcdpct
- https://vial.calltheshots.us/location/lcdpcx
- https://vial.calltheshots.us/location/lcbxdb
- https://vial.calltheshots.us/location/recMS9GHuzZ22xtdL
- https://vial.calltheshots.us/location/lcdrrg
- https://vial.calltheshots.us/location/recfnypi0z9CCJM2C
- https://vial.calltheshots.us/location/lcypx
- https://vial.calltheshots.us/location/ltwbb
- https://vial.calltheshots.us/location/lczbm
- https://vial.calltheshots.us/location/lztrr
- https://vial.calltheshots.us/location/lcbdrd
- https://vial.calltheshots.us/location/lccfwr
- https://vial.calltheshots.us/location/recBMhAC2bWrveCzr
- https://vial.calltheshots.us/location/recmuqmZbfwt90nKa
- https://vial.calltheshots.us/location/reclWWCqA2RfyVmfp
- https://vial.calltheshots.us/location/lccttd
- https://vial.calltheshots.us/location/rectTiWkaoe65SzO7
- https://vial.calltheshots.us/location/lytcm
- https://vial.calltheshots.us/location/lccfby
- https://vial.calltheshots.us/location/recjZu8MJJpFmsITV
- https://vial.calltheshots.us/location/lyrcy
- https://vial.calltheshots.us/location/recOUNjSpOKHcIVb3
- https://vial.calltheshots.us/location/lczkk
- https://vial.calltheshots.us/location/recWqQc3bG7PiKQJi
- https://vial.calltheshots.us/location/rec0ZtQq88b1BeHuL
- https://vial.calltheshots.us/location/rec4hIM15kwHmPq66
- https://vial.calltheshots.us/location/lccrzk
- https://vial.calltheshots.us/location/reciqkbZLQweaU4tb
- https://vial.calltheshots.us/location/recxc8kgcBLMWV9DM
- https://vial.calltheshots.us/location/ldfyf
- https://vial.calltheshots.us/location/ldcmp
- https://vial.calltheshots.us/location/recubUCD0Fv2fucdP
- https://vial.calltheshots.us/location/recYA30XLXT6zSchH
- https://vial.calltheshots.us/location/rec7eiAERWzxJrzTt
- https://vial.calltheshots.us/location/recrK7eVQG4JVtPlT
- https://vial.calltheshots.us/location/reckQWb1ZD601IUFL
- https://vial.calltheshots.us/location/ldfdd
- https://vial.calltheshots.us/location/ldfxw
- https://vial.calltheshots.us/location/recbECvQlveAyBorV
- https://vial.calltheshots.us/location/recTzYPYxTFkYzRjF
- https://vial.calltheshots.us/location/recCUsBAvROfKpQDM
- https://vial.calltheshots.us/location/rec22nN3WTAI0hwGp
- https://vial.calltheshots.us/location/rec9rJeUBhcP03LR6
- https://vial.calltheshots.us/location/rec7uORZu08VMzw32
- https://vial.calltheshots.us/location/recY615z31Ssf6X46
- https://vial.calltheshots.us/location/recVUHuB3bbhpqwY0
- https://vial.calltheshots.us/location/recu357xpbonyjL2P
- https://vial.calltheshots.us/location/recDyCOyJqUhQCVBR
- https://vial.calltheshots.us/location/recwaMu4Yl80NRhso
- https://vial.calltheshots.us/location/recZ2zxHVlmTtBXYy
- https://vial.calltheshots.us/location/recZ5U8tLqMsUav0M
- https://vial.calltheshots.us/location/recp8Ug9S0rwQsE9w
- https://vial.calltheshots.us/location/ldbqh
- https://vial.calltheshots.us/location/ldcxz
- https://vial.calltheshots.us/location/ldfxx
- https://vial.calltheshots.us/location/rec8Le8wbN8S28S5n
- https://vial.calltheshots.us/location/lccwbm
- https://vial.calltheshots.us/location/recp5ulEwgwPQ7Qmc
- https://vial.calltheshots.us/location/recDqx3Q7vtTGudh7
- https://vial.calltheshots.us/location/reckHwpJVYi8lGGLu
- https://vial.calltheshots.us/location/lwqtq
- https://vial.calltheshots.us/location/ldcmw
- https://vial.calltheshots.us/location/rech5w8fbSlS6qLCF
- https://vial.calltheshots.us/location/rec1UK8CsF3JcoOEV
- https://vial.calltheshots.us/location/recSeLSvVWYfBKZkg
- https://vial.calltheshots.us/location/rec4CRRjYKgQHv8oZ
- https://vial.calltheshots.us/location/lcdmpk
- https://vial.calltheshots.us/location/recU215rkMNRWOo4A
- https://vial.calltheshots.us/location/lcdcwx
- https://vial.calltheshots.us/location/lwpkk
- https://vial.calltheshots.us/location/lccbxb
- https://vial.calltheshots.us/location/lykcx
- https://vial.calltheshots.us/location/lcdpck
- https://vial.calltheshots.us/location/lzpyg
- https://vial.calltheshots.us/location/lccmdw
- https://vial.calltheshots.us/location/recgxONGtBuQ5s9yM
- https://vial.calltheshots.us/location/lcdpcw
- https://vial.calltheshots.us/location/lwwkd
- https://vial.calltheshots.us/location/lcdgqp
- https://vial.calltheshots.us/location/ldkpb
- https://vial.calltheshots.us/location/lqycd
- https://vial.calltheshots.us/location/lcdpdk
- https://vial.calltheshots.us/location/reclnu84grqDfjEb5
- https://vial.calltheshots.us/location/lccrht
- https://vial.calltheshots.us/location/reczvYUkgeAqQIISr
- https://vial.calltheshots.us/location/recAcyTytFbMSRE91
- https://vial.calltheshots.us/location/lrzyq
- https://vial.calltheshots.us/location/lrmhx
- https://vial.calltheshots.us/location/ltbfd
- https://vial.calltheshots.us/location/lcczqk
- https://vial.calltheshots.us/location/lcytk
- https://vial.calltheshots.us/location/lxcfd
- https://vial.calltheshots.us/location/lypcq
- https://vial.calltheshots.us/location/lzffc
- https://vial.calltheshots.us/location/lzrmk
- https://vial.calltheshots.us/location/ldkrq
- https://vial.calltheshots.us/location/recDXSlVhSEuPt7bI
- https://vial.calltheshots.us/location/rec4HMauRp1jIA9T5
- https://vial.calltheshots.us/location/rec7d2CdHFvQuqJz1
- https://vial.calltheshots.us/location/recEIiH5qvjUoh3dd
- https://vial.calltheshots.us/location/rec8oG4y6cgDLQSxq
- https://vial.calltheshots.us/location/lddpg
- https://vial.calltheshots.us/location/recH0BsS6hfmzVo3E
- https://vial.calltheshots.us/location/lddtt
- https://vial.calltheshots.us/location/recu6wWd4EbXgITwW
- https://vial.calltheshots.us/location/lcctqm
- https://vial.calltheshots.us/location/recfkGYoWvDu4GWGO
- https://vial.calltheshots.us/location/rec47LhdhHJhhFgFq
- https://vial.calltheshots.us/location/recFYra9ibDgu5TdP
- https://vial.calltheshots.us/location/ldbzb
- https://vial.calltheshots.us/location/recW3lUlhtPErUW4U
- https://vial.calltheshots.us/location/recBsfUisIt76xVSw
- https://vial.calltheshots.us/location/recCIMrHZrP0lMWbY
- https://vial.calltheshots.us/location/recbzIIk07HiHLVW3
- https://vial.calltheshots.us/location/recrox3LvtQWiw5T2
- https://vial.calltheshots.us/location/reckJoDQqmwbKP0Jy
- https://vial.calltheshots.us/location/rec21ms8JSp6PzEKc
- https://vial.calltheshots.us/location/lddmk
- https://vial.calltheshots.us/location/recChhQRFVXo1390W
- https://vial.calltheshots.us/location/ldbgz
- https://vial.calltheshots.us/location/lddkg
- https://vial.calltheshots.us/location/ldfdk
- https://vial.calltheshots.us/location/recyWegrnJoORzrPg
- https://vial.calltheshots.us/location/lczdx
- https://vial.calltheshots.us/location/ldfzk
- https://vial.calltheshots.us/location/lccrrd
- https://vial.calltheshots.us/location/rec0b0LMSnMjCTcJI
- https://vial.calltheshots.us/location/recCQ3mMkeNXBfcTy
- https://vial.calltheshots.us/location/recIzXSWo7PD5GqeM
- https://vial.calltheshots.us/location/recoPSp7Z1slCwviA
- https://vial.calltheshots.us/location/recMSoMRkPR4vkAFK
- https://vial.calltheshots.us/location/recyyGD94VhmfcBsW
- https://vial.calltheshots.us/location/rec7fIj8MNkkBgycH
- https://vial.calltheshots.us/location/ldczb
- https://vial.calltheshots.us/location/recbrz5cLy9ZPXyQP
- https://vial.calltheshots.us/location/lddkw
- https://vial.calltheshots.us/location/recTdow8QpoigmsQf
... and every single one of those pages is a 500 error right now.
All of those locations are soft-deleted: https://vial.calltheshots.us/dashboard/?sql=select+%27-+https%3A%2F%2Fvial.calltheshots.us%2Fadmin%2Fcore%2Flocation%2F%27+%7C%7C+location.id%2C+location.soft_deleted%0D%0Afrom+location+join+report+on+location.dn_latest_non_skip_report_id+%3D+report.id%0D%0Awhere+location.id+%21%3D+report.location_id%3A7RxSdnUXmC7u-ohRq3i29eX4EVlsch6eZ6d582VIMF4
select '- https://vial.calltheshots.us/admin/core/location/' || location.id, location.soft_deleted
from location join report on location.dn_latest_non_skip_report_id = report.id
where location.id != report.location_id
This was caused by merges. All but one of those 318 events has a populated duplicate_of_id
column - so they were merged, but the dn_latest_non_skip_report_id
column on the loser of the merge was not recalculated.
[ Need to figure out what's going on with the single location that wasn't the loser of a merge - https://vial.calltheshots.us/dashboard/?sql=select+location.id%2C+location.soft_deleted%2C+location.duplicate_of_id%2C+location.dn_latest_non_skip_report_id%2C+report.id+as+report_id%2C+report.location_id+as+report_location_id%0D%0Afrom+location+join+report+on+location.dn_latest_non_skip_report_id+%3D+report.id%0D%0Awhere+location.id+%21%3D+report.location_id%0D%0Aand+duplicate_of_id+is+null%3AIhGCoZ7Qpa2nlkCAxZT9ebxootYQihvKnHlXVqlPqa8 shows that to be 8038 which isn't soft-deleted either)
Looks like that one had a manual edit which broke the data model somehow: https://vial.calltheshots.us/admin/core/location/8038/history/compare/?version_id2=217907&version_id1=217877
Aha! The 317 locations here are a red-herring - the export script only considers not-soft-deleted locations, so they're not causing the error with the Mapbox export.
The location that is breaking things is the one @Ugaso identified, https://vial.calltheshots.us/admin/core/location/8234/history/
It looks to me like https://vial.calltheshots.us/admin/core/location/8038/history/ is the corrupt location: it was merged into https://vial.calltheshots.us/admin/core/location/8234/ BUT a later edit in the admin tool reverted those soft_deleted and duplicate_of fields back to their pre-merged state - even though the reports had been copied across.
That edit happened within an hour of the merge. My best guess is that someone had left a tab open with the edit form for that location, then when they hit "save" later it over-wrote the data from the merge.
I think I can fix that manually now (I'll re-run the merge) - then I'll make the duplicate_of field read-only in the admin to avoid this happening again in the future.
Re-running the merge using https://vial.calltheshots.us/admin/merge-locations/?winner=ldbdr&loser=lczkk
There are now zero non-soft-deleted locations with mismatching location IDs against their denormalized report IDs: https://vial.calltheshots.us/dashboard/?sql=select+location.id%2C+location.soft_deleted%2C+location.duplicate_of_id%2C+location.dn_latest_non_skip_report_id%2C+report.id+as+report_id%2C+report.location_id+as+report_location_id%0D%0Afrom+location+join+report+on+location.dn_latest_non_skip_report_id+%3D+report.id%0D%0Awhere+location.id+%21%3D+report.location_id%0D%0Aand+duplicate_of_id+is+null%3AIhGCoZ7Qpa2nlkCAxZT9ebxootYQihvKnHlXVqlPqa8
Re-ran the mapbox export by clicking the button in https://console.cloud.google.com/cloudscheduler?project=django-vaccinateca
It ran successfully.
To avoid this happening in the future, I'm going to do two things:
- Make
duplicate_of
a read-only column, which can only be edited using the merge locations tool - Introduce a validation rule that says you can't un-check the
soft_deleted
column for locations that have aduplicate_of
value.
It looks to me like https://vial.calltheshots.us/admin/core/location/8038/history/ is the corrupt location: it was merged into https://vial.calltheshots.us/admin/core/location/8234/ BUT a later edit in the admin tool reverted those soft_deleted and duplicate_of fields back to their pre-merged state - even though the reports had been copied across.
TY for solving this! What an interesting bug.
How were you able to track the merge history of that location? I found it! Merged location dashboard details this well: https://vial.calltheshots.us/dashboard/merged-locations/