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

Panic on adding a foreign key constraint #3010

Closed
VinaiRachakonda opened this issue Mar 16, 2022 · 2 comments
Closed

Panic on adding a foreign key constraint #3010

VinaiRachakonda opened this issue Mar 16, 2022 · 2 comments
Assignees
Labels
bug Something isn't working ORM Issue caused from ORM usage

Comments

@VinaiRachakonda
Copy link
Contributor

Consider the following dump

DROP TABLE IF EXISTS `a`;
CREATE TABLE `a` (
  `id` int NOT NULL AUTO_INCREMENT,
  `a` text NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO `a` (`id`,`a`) VALUES (1,'a');
DROP TABLE IF EXISTS `b`;
CREATE TABLE `b` (
  `id` int NOT NULL AUTO_INCREMENT,
  `b` text NOT NULL,
  `a_id` int,
  PRIMARY KEY (`id`),
  KEY `b_a_id` (`a_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO `b` (`id`,`b`,`a_id`) VALUES (1,'b',NULL);
INSERT INTO `b` (`id`,`b`,`a_id`) VALUES (2,'b2',31337);
INSERT INTO `b` (`id`,`b`,`a_id`) VALUES (3,'b2',31337);
INSERT INTO `b` (`id`,`b`,`a_id`) VALUES (4,'b2',31337);

The following query causes a panic

ALTER TABLE `b` ADD CONSTRAINT `fk_b_a_id_refs_a` FOREIGN KEY (`a_id`) REFERENCES `a` (`id`);
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x16b6fdc]

goroutine 1 [running]:
github.com/dolthub/dolt/go/store/types.newSequenceImpl(...)
	/Users/vinairachakonda/go/src/dolthub/dolt/go/store/types/sequence.go:75
github.com/dolthub/dolt/go/store/types.newLeafSequence({0x0, 0x0}, {0xc000a6a38a, 0x5, 0x2e}, {0xc0006c6c80, 0x5, 0x8}, 0x2)
	/Users/vinairachakonda/go/src/dolthub/dolt/go/store/types/leaf_sequence.go:36 +0x7c
github.com/dolthub/dolt/go/store/types.(*valueDecoder).readSequence(0xc000a25480, 0xc0004fa640, 0x1, 0xc000530210)
	/Users/vinairachakonda/go/src/dolthub/dolt/go/store/types/value_decoder.go:179 +0x3ad
github.com/dolthub/dolt/go/store/types.(*valueDecoder).readBlobSequence(0xfd5, 0x100e625)
	/Users/vinairachakonda/go/src/dolthub/dolt/go/store/types/value_decoder.go:183 +0x4c
github.com/dolthub/dolt/go/store/types.(*valueDecoder).readValue(0xc000a25480, 0xc000a25440)
	/Users/vinairachakonda/go/src/dolthub/dolt/go/store/types/value_decoder.go:321 +0x116
github.com/dolthub/dolt/go/store/types.(*TupleIterator).Next(0xc00069ada0)
	/Users/vinairachakonda/go/src/dolthub/dolt/go/store/types/tuple.go:125 +0x3e
github.com/dolthub/dolt/go/store/types.Tuple.IterFields({{{0x0, 0x0}, 0x3a66710, {0xc000a6a380, 0x16, 0x38}, {0x0, 0x0, 0x0}}}, 0xc000530940)
	/Users/vinairachakonda/go/src/dolthub/dolt/go/store/types/tuple.go:537 +0x1af
github.com/dolthub/dolt/go/store/types.(*hrsWriter).Write(0xc000a25440, {0x2b83e00, 0xc00019a000}, {0x2bc8900, 0xc000a67680})
	/Users/vinairachakonda/go/src/dolthub/dolt/go/store/types/encode_human_readable.go:236 +0xd8c
github.com/dolthub/dolt/go/store/types.encodedValueFormat({0x2b83e00, 0xc00019a000}, {0x2bc8900, 0xc000a67680}, 0x67)
	/Users/vinairachakonda/go/src/dolthub/dolt/go/store/types/encode_human_readable.go:545 +0xa5
github.com/dolthub/dolt/go/store/types.EncodedValue(...)
	/Users/vinairachakonda/go/src/dolthub/dolt/go/store/types/encode_human_readable.go:564
github.com/dolthub/dolt/go/libraries/doltcore/doltdb.(*ForeignKeyViolationError).Error(0xc000d36540)
	/Users/vinairachakonda/go/src/dolthub/dolt/go/libraries/doltcore/doltdb/foreign_key_coll.go:66 +0x4ef
github.com/dolthub/dolt/go/cmd/dolt/errhand.VerboseErrorFromError({0x2b4c0c0, 0xc000d36540})
	/Users/vinairachakonda/go/src/dolthub/dolt/go/cmd/dolt/errhand/derr.go:119 +0x62
github.com/dolthub/dolt/go/cmd/dolt/commands.formatQueryError({0x0, 0xc0006587e0}, {0x2b4c0c0, 0xc000d36540})
	/Users/vinairachakonda/go/src/dolthub/dolt/go/cmd/dolt/commands/sql.go:536 +0x3a8
github.com/dolthub/dolt/go/cmd/dolt/commands.runShell.func3.1({0x2b83e70, 0xc00002a6f0}, 0xc0000ec8a0, 0xc0008e40a0, 0xc000114620, 0xc000120000, {0xc0006587e0, 0x5c}, 0xc000531268, 0xc000531228, ...)
	/Users/vinairachakonda/go/src/dolthub/dolt/go/cmd/dolt/commands/sql.go:840 +0x43b
github.com/dolthub/dolt/go/cmd/dolt/commands.runShell.func3(0xc000120000)
	/Users/vinairachakonda/go/src/dolthub/dolt/go/cmd/dolt/commands/sql.go:851 +0x48c
github.com/dolthub/ishell.handleUninterpretedInput(0xc000120000, {0xc0006587e0, 0x1})
	/Users/vinairachakonda/go/pkg/mod/github.com/dolthub/ishell@v0.0.0-20220112232610-14e753f0f371/ishell.go:288 +0x144
github.com/dolthub/ishell.(*Shell).run(0xc000120000)
	/Users/vinairachakonda/go/pkg/mod/github.com/dolthub/ishell@v0.0.0-20220112232610-14e753f0f371/ishell.go:245 +0x326
github.com/dolthub/ishell.(*Shell).Run(0xc000120000)
	/Users/vinairachakonda/go/pkg/mod/github.com/dolthub/ishell@v0.0.0-20220112232610-14e753f0f371/ishell.go:139 +0x28
github.com/dolthub/dolt/go/cmd/dolt/commands.runShell({0x2b83e70, 0xc00002a6f0}, 0xc0000ec8a0, 0x2b83e70)
	/Users/vinairachakonda/go/src/dolthub/dolt/go/cmd/dolt/commands/sql.go:861 +0x76d
github.com/dolthub/dolt/go/cmd/dolt/commands.execShell({0x2b83e70, 0xc00002a6f0}, 0x281b8b2, 0x4, {0xc0001c69dc, 0x4b8})
	/Users/vinairachakonda/go/src/dolthub/dolt/go/cmd/dolt/commands/sql.go:383 +0xd2
github.com/dolthub/dolt/go/cmd/dolt/commands.SqlCmd.Exec({{0x281d757, 0xc0005f1900}}, {0x2b83e70, 0xc00002a6f0}, {0xc0006dc600, 0x8}, {0xc0001ac010, 0x0, 0x0}, 0xc0006f40b0)
	/Users/vinairachakonda/go/src/dolthub/dolt/go/cmd/dolt/commands/sql.go:233 +0x6bc
github.com/dolthub/dolt/go/cmd/dolt/cli.SubCommandHandler.handleCommand({{0x281b836, 0x4}, {0x2834585, 0x11}, {0x0, 0x0}, {0xc0003c02c0, 0x2b, 0x2b}, 0x0}, ...)
	/Users/vinairachakonda/go/src/dolthub/dolt/go/cmd/dolt/cli/command.go:222 +0x282
github.com/dolthub/dolt/go/cmd/dolt/cli.SubCommandHandler.Exec({{0x281b836, 0x4}, {0x2834585, 0x11}, {0x0, 0x0}, {0xc0003c02c0, 0x2b, 0x2b}, 0x0}, ...)
	/Users/vinairachakonda/go/src/dolthub/dolt/go/cmd/dolt/cli/command.go:179 +0x47f
main.runMain()
	/Users/vinairachakonda/go/src/dolthub/dolt/go/cmd/dolt/dolt.go:345 +0x6e5
main.main()
	/Users/vinairachakonda/go/src/dolthub/dolt/go/cmd/dolt/dolt.go:131 +0x19
@VinaiRachakonda VinaiRachakonda added bug Something isn't working ORM Issue caused from ORM usage labels Mar 16, 2022
@VinaiRachakonda
Copy link
Contributor Author

This is blocking the peewee ORM

@jennifersp jennifersp self-assigned this Apr 5, 2022
@jennifersp jennifersp linked a pull request Apr 6, 2022 that will close this issue
@jennifersp jennifersp removed a link to a pull request Apr 20, 2022
@jennifersp
Copy link
Contributor

is fixed in 8516471

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ORM Issue caused from ORM usage
Projects
None yet
Development

No branches or pull requests

2 participants