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

import: Fix import of Stream.creator field. #30081

Merged
merged 1 commit into from
May 14, 2024

Conversation

mateuszmandera
Copy link
Contributor

When importing a Stream, UserProfiles don't yet exist. so trying to import stream.creator fails with something like:

psycopg2.errors.ForeignKeyViolation: insert or update on table
"zerver_stream" violates foreign key constraint
"zerver_stream_creator_id_65aeba7e_fk_zerver_userprofile_id"
DETAIL:  Key (creator_id)=(5) is not present in table "zerver_userprofile".

Comment on lines +1019 to +1023
imported_hamlet_user = UserProfile.objects.get(
delivery_email=self.example_email("hamlet"), realm=imported_realm
)
imported_denmark_stream = Stream.objects.get(name="Denmark", realm=imported_realm)
self.assertEqual(imported_denmark_stream.creator, imported_hamlet_user)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently this doesn't actually fail without the fix above; because tests run inside a transaction. Not sure how to simulate the real situation in this test reasonably... But verified manually that the original code fails to import if there's a stream with .creator set, and after this fix it's able to be imported correctly.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably that's good enough.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#30082 fails(error) without this fix.

When importing a Stream, UserProfiles don't yet exist. so trying to
import stream.creator fails with something like:

```
psycopg2.errors.ForeignKeyViolation: insert or update on table
"zerver_stream" violates foreign key constraint
"zerver_stream_creator_id_65aeba7e_fk_zerver_userprofile_id"
DETAIL:  Key (creator_id)=(5) is not present in table "zerver_userprofile".
```
@timabbott timabbott merged commit 160076f into zulip:main May 14, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants