Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrity constraint violation with Project Config #90

Closed
engram-design opened this issue Feb 27, 2020 · 17 comments · Fixed by #93
Closed

Integrity constraint violation with Project Config #90

engram-design opened this issue Feb 27, 2020 · 17 comments · Fixed by #93
Assignees
Labels
Bug Report Something isn't working

Comments

@engram-design
Copy link

Had the following issue after editing blocks locally, and pushing to production.

Applying changes from project.yaml ... error: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'matrixBlockTypeId' cannot be null
The SQL being executed was: INSERT INTO `spoon_blocktypes` (`fieldId`, `matrixBlockTypeId`, `groupName`, `context`, `uid`, `fieldLayoutId`, `dateCreated`, `dateUpdated`) VALUES (127, NULL, 'Content', 'global', '577d299d-31b9-4451-b793-05bb8b88726e', 238, '2020-02-27 22:21:10', '2020-02-27 22:21:10')

This also left 10 out of 13 block types 'reset' so I had to set them up through Spoon again.

@qrazi
Copy link
Contributor

qrazi commented Mar 5, 2020

Running into this too, Craft CMS 3.4.9 and Spoon 3.5.2. The matrixBlockType in question is new, defined in project.yaml by another developer. So probably for some reason Spoon tries to add a record that is not added by Craft yet (as I cannot find this record in my DB. But that could also be due to failed transactions?).

@qrazi
Copy link
Contributor

qrazi commented Mar 5, 2020

Should probably do a check similar to: https://github.com/craftcms/cms/blob/develop/src/services/Matrix.php#L325

@joshangell
Copy link
Contributor

@qrazi you hero, thanks for finding that! If you want to PR it that would be a big help.

@joshangell joshangell self-assigned this Mar 5, 2020
@joshangell joshangell added the Bug Report Something isn't working label Mar 5, 2020
@joshangell joshangell pinned this issue Mar 5, 2020
@qrazi
Copy link
Contributor

qrazi commented Mar 5, 2020

@joshangell I am still testing / investigating on my end, but I'll try and isolate this bug and do a PR (the issues on my end include more things than just this one... 😬 )

@joshangell
Copy link
Contributor

@qrazi aaaah sorry about that, there are an increasing number of edge case bugs popping up that are frustratingly time consuming to fix!

@qrazi
Copy link
Contributor

qrazi commented Mar 5, 2020

@joshangell No worries! I mean in the project I am working, not specifically this plugin 😅

@qrazi
Copy link
Contributor

qrazi commented Mar 5, 2020

Ok, things are up running on my environment again, and right now I do not need the check similar to the Matrix-service. The other issues I kept running into when syncing the project.yaml were cause by duplicate MatrixBlockFields.

I am still not a 100% why that ended up in Spoon trying to insert a record before the accompanying MatrixBlockField was inserted, but probably because when searching based on handle it would have given a result somewhere. The Craft CMS ecosystem uses both handles and uids. Not that long ago this used to be solely based on handles, so duplicating handles was actually a lot more difficult. We're now in this mixed code that on the one hand allows create duplicate handles, but on the other hand always expects a handle to be unique.

I am not sure if the cause is similar for @engram-design error? I will create a PR anyway, but I think it might solve a symptom, not a cause.

@engram-design
Copy link
Author

So, I believe what happened at the time, was the Matrix blocks themselves didn't update, or something went wrong, and due to that, Spoon tried to do its thing without having the Matrix blocks properly sorted first.

It's all a bit vague, but it was pretty urgent to fix at the time, so had to revert things, and manually set things up from scratch.

@qrazi
Copy link
Contributor

qrazi commented Mar 6, 2020

So, I believe what happened at the time, was the Matrix blocks themselves didn't update, or something went wrong, and due to that, Spoon tried to do its thing without having the Matrix blocks properly sorted first.

It's all a bit vague, but it was pretty urgent to fix at the time, so had to revert things, and manually set things up from scratch.

Yes, we've been doing that a lot too. It's really easy to get these kind of issues in Craft CMS. Development discipline remains key. However, the PR would point developers a bit more in the right direction I think.

@davist11
Copy link

davist11 commented May 12, 2020

Was there any sort of resolution to this problem? I'm seeing the same thing happen that it's trying to sync the spoon config before the matrix block types exist.

@dennisfrank
Copy link

I am running into this too. @engram-design Have you checked PR #93?

@dennisfrank
Copy link

?

@engram-design
Copy link
Author

@dennisfrank Haven't tried the PR - did it work for you?

@cherrykoda
Copy link

Just ran into this myself - any word?

@davist11
Copy link

We've started to switch some projects over to https://plugins.craftcms.com/matrixmate since there hasn't been much action here. Just in case that could be helpful to anyone.

@joshangell
Copy link
Contributor

I can finally reproduce this! Will be aiming to fix asap.

@joshangell
Copy link
Contributor

OK - seems like the PR #93 fixes this - have tested against my reproducible case an it fixes that, though I’m not going to rule out it not fixing other situations so please do re-open this if that is the case.

joshangell added a commit that referenced this issue Jul 30, 2020
- Fixed an issue where project config could fail with an "Integrity constraint violation" error - thanks to [@qrazi](https://github.com/qrazi) for pointing me in the right direction! ([#90](#90) & [PR #93](#93))
- Fixed an issue with newer versions of Super Table which caused Matrix blocks to render empty if there was at least one Super Table configured inside the Matrix field ([#98](#98))
- Fixed an error that could occur when matrix fields don’t return properly by ID ([#92](#92))
@joshangell joshangell unpinned this issue Jul 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Report Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants