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

Zulip - RocketChat - Data Converter #20108

Open
talheim-it opened this issue Oct 30, 2021 · 47 comments · May be fixed by #20196
Open

Zulip - RocketChat - Data Converter #20108

talheim-it opened this issue Oct 30, 2021 · 47 comments · May be fixed by #20196

Comments

@talheim-it
Copy link

talheim-it commented Oct 30, 2021

Hello!

I installed Zulip from Git and tried to run the convert_rocketchat_data script.

Zulip Version: 5.0-dev-2500-g73710e1cf0
RocketChat Version: 4.0

Server Specifications:
OS: Ubuntu 20.04.3 LTS
CPU: 4
Memory: 16GB RAM
SWAP: 4GB

The migration looks like following:

zulip@comm01:~$ ./deployments/current/manage.py convert_rocketchat_data /home/zulip/rocketchat --output /home/zulip/converted_rocketchat_data
Converting Data ...
Killed

The situation is that it seems that the converter fails at some point but I don't know where. I also tried to run it with traceback but no additional infos were shown.

@timabbott
Copy link
Sponsor Member

@talheim-it that error message is for an out-of-memory failure. If you are running the tool on a Zullip server with minimal memory, I'd recommend shutting down the Zulip server with scripts/stop-server before running the conversion tool.

It's also possible that either you have a very large Rocket.Chat dataset or there's a bug with the conversation tool that makes it consume more memory than it should; we should investigate those possibilities if shutting down the server while you run the conversion doesn't work.

@zulipbot
Copy link
Member

zulipbot commented Nov 1, 2021

Hello @zulip/server-misc members, this issue was labeled with the "area: export/import" label, so you may want to check it out!

@rht
Copy link
Collaborator

rht commented Nov 1, 2021

Is this specific to the Rocket.Chat data conversion? IIRC the Slack version scales nicely to large data.

@talheim-it
Copy link
Author

@timabbott I am testing it today. Thanks for the info

@talheim-it
Copy link
Author

talheim-it commented Nov 1, 2021

@timabbott I run into the next issue after I increased the memory to 16GB of the vm:

zulip@comm01:~$ ./deployments/current/manage.py convert_rocketchat_data /home/zulip/rocketchat --traceback --output /home/zulip/converted_rocketchat_data
Converting Data ...
Traceback (most recent call last):
  File "./deployments/current/manage.py", line 157, in <module>
    execute_from_command_line(sys.argv)
  File "./deployments/current/manage.py", line 122, in execute_from_command_line
    utility.execute()
  File "/srv/zulip-venv-cache/e37db4daafc6d0d0d8c6567993ceba763eb2c1ed/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/srv/zulip-venv-cache/e37db4daafc6d0d0d8c6567993ceba763eb2c1ed/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/srv/zulip-venv-cache/e37db4daafc6d0d0d8c6567993ceba763eb2c1ed/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/opt/zulip/deployments/2021-10-30-17-45-02/zerver/management/commands/convert_rocketchat_data.py", line 45, in handle
    do_convert_data(rocketchat_data_dir=data_dir, output_dir=output_dir)
  File "/opt/zulip/deployments/2021-10-30-17-45-02/zerver/data_import/rocketchat.py", line 919, in do_convert_data
    zerver_stream = convert_channel_data(
  File "/opt/zulip/deployments/2021-10-30-17-45-02/zerver/data_import/rocketchat.py", line 152, in convert_channel_data
    stream_name = channel_dict["name"]
KeyError: 'name'

Seems like an issue with the channel conversion?

Btw you can ignore the path. I set a symlink from /home/zulip to /opt/zulip to install it there since I want to exchange the existent rocket.chat server with it.

@talheim-it
Copy link
Author

Added additional informations about the server to the issue.

@talheim-it
Copy link
Author

@rht I only tested it with Rocket.Chat. I takes a lot memory. I see it permanently Growing. Before all was fine with 4 CPUs, 8GB Memory, 4GB Swap. Now I had to double the Memory to 16GB to get the next error.

@timabbott
Copy link
Sponsor Member

@talheim-it with your new exception, can you print(channel_dict) on the line before that failure? That should hopefully provide the information needed to debug.

@talheim-it
Copy link
Author

@timabbott

I added it on line 152, before the error occurs in the rocketchat.py:

for rc_room_id in room_id_to_room_map:
        channel_dict = room_id_to_room_map[rc_room_id]

        date_created = float(channel_dict["ts"].timestamp())
        stream_id = stream_id_mapper.get(rc_room_id)
        invite_only = channel_dict["t"] == "p"

        print(channel_dict)
        stream_name = channel_dict["name"]
        stream_desc = channel_dict.get("description", "")
        if channel_dict.get("teamId"):
            if channel_dict.get("teamMain") is True:
                # In case you change this, please also change the stream name
                # used while adding the Rocket.Chat channel mention data to
                # message_dict in `message_to_dict` inner-function of
                # `process_messages` function below.
                stream_name = "[TEAM] " + stream_name
            else:
                stream_desc = "[Team {} channel]. {}".format(
                    team_id_to_team_map[channel_dict["teamId"]]["name"], stream_desc
                )

        # If the channel is read-only, then only admins and moderators
        # should be allowed to post in the converted Zulip stream.
        # For more details: https://zulip.com/help/stream-sending-policy
        #
        # See `Stream` model in `zerver/models.py` to know about what each
        # number represent.
        stream_post_policy = 4 if channel_dict.get("ro", False) else 1

This is the output:

zulip@comm01:~$ ./deployments/current/manage.py convert_rocketchat_data /home/zulip/rocketchat --traceback --output /home/zulip/converted_rocketchat_data
ssConverting Data ...
{'_id': '2t6Lyzd2KAD3nS8Ch', 'msgs': 20, 'usersCount': 1, 'lm': datetime.datetime(2019, 2, 24, 23, 26, 12, 732000), 'fname': 'guest-6', 't': 'l', 'ts': datetime.datetime(2019, 2, 21, 16, 59, 48, 523000), 'v': {'_id': '4ofuMYKZcbE4Qe93v', 'username': 'guest-6', 'token': 'G3iTCBA9dtBwuDs7Z', 'status': 'offline'}, 'servedBy': {'_id': '5KuA73x4LHsFibyqP', 'username': 'mathias.rumbold', 'ts': datetime.datetime(2019, 2, 21, 16, 59, 48, 523000)}, 'cl': False, '_updatedAt': datetime.datetime(2019, 2, 24, 23, 26, 12, 796000), 'lastMessage': {'t': 'livechat-close', 'msg': '', 'groupable': False, 'ts': datetime.datetime(2019, 2, 24, 23, 26, 12, 732000), 'u': {'_id': '5KuA73x4LHsFibyqP', 'username': 'mathias.rumbold', 'name': 'Mathias Rumbold'}, 'rid': '2t6Lyzd2KAD3nS8Ch', '_id': 'rZxeE3kSvwfrQ5DWc', '_updatedAt': datetime.datetime(2019, 2, 24, 23, 26, 12, 750000), 'mentions': [], 'channels': [], 'sandstormSessionId': None}, 'metrics': {'v': {'lq': datetime.datetime(2019, 2, 21, 17, 7, 18, 434000)}, 'reaction': {'fd': datetime.datetime(2019, 2, 21, 17, 0, 8, 327000), 'ft': 19.804, 'tt': 100.50500000000001}, 'response': {'avg': 20.0934, 'fd': datetime.datetime(2019, 2, 21, 17, 0, 8, 327000), 'ft': 19.766, 'total': 5, 'tt': 100.467}, 'servedBy': {'lr': datetime.datetime(2019, 2, 21, 17, 7, 37, 109000)}, 'chatDuration': 282384.191}, 'responseBy': {'_id': '5KuA73x4LHsFibyqP', 'username': 'mathias.rumbold'}, 'closedAt': datetime.datetime(2019, 2, 24, 23, 26, 12, 714000), 'closedBy': {'_id': '5KuA73x4LHsFibyqP', 'username': 'mathias.rumbold'}, 'closer': 'user'}
Traceback (most recent call last):
  File "./deployments/current/manage.py", line 157, in <module>
    execute_from_command_line(sys.argv)
  File "./deployments/current/manage.py", line 122, in execute_from_command_line
    utility.execute()
  File "/srv/zulip-venv-cache/e37db4daafc6d0d0d8c6567993ceba763eb2c1ed/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/srv/zulip-venv-cache/e37db4daafc6d0d0d8c6567993ceba763eb2c1ed/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/srv/zulip-venv-cache/e37db4daafc6d0d0d8c6567993ceba763eb2c1ed/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/opt/zulip/deployments/2021-10-30-17-45-02/zerver/management/commands/convert_rocketchat_data.py", line 45, in handle
    do_convert_data(rocketchat_data_dir=data_dir, output_dir=output_dir)
  File "/opt/zulip/deployments/2021-10-30-17-45-02/zerver/data_import/rocketchat.py", line 920, in do_convert_data
    zerver_stream = convert_channel_data(
  File "/opt/zulip/deployments/2021-10-30-17-45-02/zerver/data_import/rocketchat.py", line 153, in convert_channel_data
    stream_name = channel_dict["name"]
KeyError: 'name'

@talheim-it
Copy link
Author

@timabbott anything else I can do here? I am stucked within the migration.

@timabbott
Copy link
Sponsor Member

@garg3133 FYI as the original author of the tool; can you help debug?

@timabbott
Copy link
Sponsor Member

I haven't read this format, but I think what's going on is that Rocket.Chat's Omnichannel/livechat channels use the fname field ("guest-6" here) rather than name for some reason to identify the channel. Can you check if the tool completes replacing that line with

stream_name = channel_dict.get("name", channel_dict["fname"])

?

It's likely that a better choice for how to structure the import would be to put these all in a single Rocket.Chat omnichannel stream with fname as the topic or something like that, but this should let the job complete.

@garg3133
Copy link
Member

garg3133 commented Nov 3, 2021

Yes, Rocket.Chat uses the fname field to specify the channel names of Livechat and Discussions, and that's what is causing this error.

I've opened #20153, which should fix this.

It's likely that a better choice for how to structure the import would be to put these all in a single Rocket.Chat omnichannel stream with fname as the topic or something like that, but this should let the job complete.

Yes, that's what I was thinking.

@talheim-it
Copy link
Author

talheim-it commented Nov 4, 2021

@garg3133 thanks, I have another issue now:

Background: The user is not existing anymore as user, so it seems that the error occurs because the reaction is still in the database, but the user not.

Converting Data ...
2021-11-04 10:50:33.827 INFO [] Starting to process custom emoji
2021-11-04 10:50:33.895 INFO [] Done processing emoji
Traceback (most recent call last):
  File "./deployments/current/manage.py", line 157, in <module>
    execute_from_command_line(sys.argv)
  File "./deployments/current/manage.py", line 122, in execute_from_command_line
    utility.execute()
  File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/opt/zulip/deployments/2021-11-04-11-29-20/zerver/management/commands/convert_rocketchat_data.py", line 45, in handle
    do_convert_data(rocketchat_data_dir=data_dir, output_dir=output_dir)
  File "/opt/zulip/deployments/2021-11-04-11-29-20/zerver/data_import/rocketchat.py", line 1067, in do_convert_data
    process_messages(
  File "/opt/zulip/deployments/2021-11-04-11-29-20/zerver/data_import/rocketchat.py", line 737, in process_messages
    raw_messages.append(message_to_dict(message))
  File "/opt/zulip/deployments/2021-11-04-11-29-20/zerver/data_import/rocketchat.py", line 623, in message_to_dict
    reactions = list_reactions(message["reactions"])
  File "/opt/zulip/deployments/2021-11-04-11-29-20/zerver/data_import/rocketchat.py", line 611, in list_reactions
    rc_user_id = username_to_user_id_map[username]
KeyError: 'username'

Any option to handle this?

"username" at KeyError is a placeholder for the username.

@garg3133
Copy link
Member

garg3133 commented Nov 4, 2021

@talheim-it You can try changing the line to:

rc_user_id = username_to_user_id_map.get(username)

And then add the following below it:

if not rc_user_id:
    continue

So, the complete block of code will be:

for username in usernames:
    rc_user_id = username_to_user_id_map.get(username)
    if not rc_user_id:
        continue
    user_id = user_id_mapper.get(rc_user_id)
    reactions_list.append({"name": name, "user_id": user_id})

@staffcop
Copy link

staffcop commented Nov 4, 2021

after applying all patches mentioned here, even latest one from @garg3133

Converting Data ... Traceback (most recent call last): File "./manage.py", line 157, in <module> execute_from_command_line(sys.argv) File "./manage.py", line 122, in execute_from_command_line utility.execute() File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv self.execute(*args, **cmd_options) File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute output = self.handle(*args, **options) File "/home/zulip/deployments/2021-11-04-19-55-46/zerver/management/commands/convert_rocketchat_data.py", line 45, in handle do_convert_data(rocketchat_data_dir=data_dir, output_dir=output_dir) File "/home/zulip/deployments/2021-11-04-19-55-46/zerver/data_import/rocketchat.py", line 951, in do_convert_data process_users( File "/home/zulip/deployments/2021-11-04-19-55-46/zerver/data_import/rocketchat.py", line 93, in process_users full_name = user_dict["name"] KeyError: 'name'

@talheim-it
Copy link
Author

@staffcop did you install the latest Version from git plus added the last change?

@staffcop
Copy link

staffcop commented Nov 4, 2021

@staffcop did you install the latest Version from git plus added the last change?

yes I had to increase memory to 16gb, upgrade to main git version, and now I am fiddling inside rocketchat.py

@garg3133
Copy link
Member

garg3133 commented Nov 4, 2021

@staffcop Can you put a print(user_dict) statement just before Line 93 and share the output logged out just before the error?

@talheim-it
Copy link
Author

@garg3133

I updated it as above:

            for username in usernames:
                rc_user_id = username_to_user_id_map.get[username]
                if not rc_user_id:
                    continue
                user_id = user_id_mapper.get(rc_user_id)
                reactions_list.append({"name": name, "user_id": user_id})

Now it throws following info:

zulip@comm01:~$ ./deployments/current/manage.py convert_rocketchat_data /home/zulip/rocketchat --traceback --output /home/zulip/converted_rocketchat_data
Converting Data ...
2021-11-04 21:29:50.871 INFO [] Starting to process custom emoji
2021-11-04 21:29:50.918 INFO [] Done processing emoji
Traceback (most recent call last):
  File "./deployments/current/manage.py", line 157, in <module>
    execute_from_command_line(sys.argv)
  File "./deployments/current/manage.py", line 122, in execute_from_command_line
    utility.execute()
  File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/management/commands/convert_rocketchat_data.py", line 45, in handle
    do_convert_data(rocketchat_data_dir=data_dir, output_dir=output_dir)
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/data_import/rocketchat.py", line 1069, in do_convert_data
    process_messages(
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/data_import/rocketchat.py", line 739, in process_messages
    raw_messages.append(message_to_dict(message))
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/data_import/rocketchat.py", line 625, in message_to_dict
    reactions = list_reactions(message["reactions"])
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/data_import/rocketchat.py", line 611, in list_reactions
    rc_user_id = username_to_user_id_map.get[username]
TypeError: 'builtin_function_or_method' object is not subscriptable

I am trying to debug it.

@garg3133
Copy link
Member

garg3133 commented Nov 4, 2021

@talheim-it Actually it's username_to_user_id_map.get(username) and not username_to_user_id_map.get[username] :)

@talheim-it
Copy link
Author

@garg3133 , you are absolutely right, my fault :)

Just a new issue:

Traceback (most recent call last):
  File "./deployments/current/manage.py", line 157, in <module>
    execute_from_command_line(sys.argv)
  File "./deployments/current/manage.py", line 122, in execute_from_command_line
    utility.execute()
  File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/management/commands/convert_rocketchat_data.py", line 45, in handle
    do_convert_data(rocketchat_data_dir=data_dir, output_dir=output_dir)
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/data_import/rocketchat.py", line 1069, in do_convert_data
    process_messages(
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/data_import/rocketchat.py", line 758, in process_messages
    process_list_in_batches(
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/lib/utils.py", line 108, in process_list_in_batches
    process_batch(items)
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/data_import/rocketchat.py", line 742, in process_batch
    process_raw_message_batch(
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/data_import/rocketchat.py", line 475, in process_raw_message_batch
    content = fix_mentions(
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/data_import/rocketchat.py", line 447, in fix_mentions
    user = user_handler.get_user(user_id=user_id)
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/data_import/user_handler.py", line 22, in get_user
    user = self.id_to_user_map[user_id]
KeyError: 116

@talheim-it
Copy link
Author

@garg3133 I try to understand the KeyError. Is it related to the user_id?

@staffcop
Copy link

staffcop commented Nov 4, 2021 via email

@talheim-it
Copy link
Author

@garg3133 if I can do anything here or send you the dump to check please let me know :)

@garg3133
Copy link
Member

garg3133 commented Nov 5, 2021

@talheim-it This error must also be due to the deleted user you told earlier about. Can you try putting the line 447

user = user_handler.get_user(user_id=user_id)

inside try-except block? The code would be something like this:

for user_id in mention_user_ids:
    try:
        user = user_handler.get_user(user_id=user_id)
    except KeyError:
        continue
    rc_mention = "@{short_name}".format(**user)
    zulip_mention = "@**{full_name}**".format(**user)
    content = content.replace(rc_mention, zulip_mention)

@talheim-it
Copy link
Author

@garg3133 seems it worked but hanging at another key:

Traceback (most recent call last):
  File "./deployments/current/manage.py", line 157, in <module>
    execute_from_command_line(sys.argv)
  File "./deployments/current/manage.py", line 122, in execute_from_command_line
    utility.execute()
  File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/management/commands/convert_rocketchat_data.py", line 45, in handle
    do_convert_data(rocketchat_data_dir=data_dir, output_dir=output_dir)
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/data_import/rocketchat.py", line 1077, in do_convert_data
    process_messages(
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/data_import/rocketchat.py", line 766, in process_messages
    process_list_in_batches(
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/lib/utils.py", line 108, in process_list_in_batches
    process_batch(items)
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/data_import/rocketchat.py", line 750, in process_batch
    process_raw_message_batch(
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/data_import/rocketchat.py", line 507, in process_raw_message_batch
    attachment_content, has_image = process_message_attachment(
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/data_import/rocketchat.py", line 411, in process_message_attachment
    user_profile_email=user_handler.get_user(user_id=user_id)["email"],
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/data_import/user_handler.py", line 22, in get_user
    user = self.id_to_user_map[user_id]
KeyError: 96

@garg3133
Copy link
Member

garg3133 commented Nov 5, 2021

Try replacing

    upload = dict(
        path=s3_path,
        realm_id=realm_id,
        content_type=upload["type"],
        user_profile_id=user_id,
        last_modified=fileinfo["created"],
        user_profile_email=user_handler.get_user(user_id=user_id)["email"],
        s3_path=s3_path,
        size=fileinfo["size"],
    )

with

    try:
        user_profile_email = user_handler.get_user(user_id=user_id)["email"]
    except KeyError:
        user_profile_email = "dummyemail@email.com"  # or any other dummy email

    upload = dict(
        path=s3_path,
        realm_id=realm_id,
        content_type=upload["type"],
        user_profile_id=user_id,
        last_modified=fileinfo["created"],
        user_profile_email=user_profile_email,
        s3_path=s3_path,
        size=fileinfo["size"],
    )

@talheim-it
Copy link
Author

@garg3133 did:

Traceback (most recent call last):
  File "./deployments/current/manage.py", line 157, in <module>
    execute_from_command_line(sys.argv)
  File "./deployments/current/manage.py", line 122, in execute_from_command_line
    utility.execute()
  File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/management/commands/convert_rocketchat_data.py", line 45, in handle
    do_convert_data(rocketchat_data_dir=data_dir, output_dir=output_dir)
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/data_import/rocketchat.py", line 1108, in do_convert_data
    process_messages(
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/data_import/rocketchat.py", line 752, in process_messages
    raw_messages.append(message_to_dict(message))
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/data_import/rocketchat.py", line 635, in message_to_dict
    content = message["msg"]
KeyError: 'msg'

I owe you something for your work on this, I am open to fund it with 100,00€ as support.

@garg3133
Copy link
Member

garg3133 commented Nov 5, 2021

@talheim-it Can you put a print(message) statement above line 635 and share the last output you get right before the error? msg field stores the content of the message, so I'm not sure what kind of message is this without any content.

Thanks a lot for your offer, but I'm not really sure if I'm allowed to take it. I'd have to consult someone from the Zulip core team.

@talheim-it
Copy link
Author

@garg3133 there we go:

This is the last message:

{'_id': '8kqKbt3kNJiRGtHtC', 'rid': '5KuA73x4LHsFibyqPisaKY25KJaTmDMzSW', 'u': {'_id': '5KuA73x4LHsFibyqP', 'username': 'mathias.rumbold', 'name': 'Mathias Rumbold'}, 'ts': datetime.datetime(2020, 4, 10, 16, 27, 58, 559000), '_updatedAt': datetime.datetime(2020, 4, 10, 16, 27, 58, 559000), 'attachments': [{'text': '', 'author_name': 'username', 'author_icon': '/avatar/username', 'message_link': '/direct?msg=B5HAcM5sZ7LKNdfAd', 'attachments': [{'ts': '1970-01-01T00:00:00.000Z', 'title': 'Booklet-4 copy.png', 'title_link': '/file-upload/ez8vaZThSraEAtRoh/Booklet-4%20copy.png', 'title_link_download': True, 'image_dimensions': {'width': 3944, 'height': 3944}, 'image_preview': '/9j/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAAgACADASIAAhEBAxEB/8QAGgAAAQUBAAAAAAAAAAAAAAAABgACBQcIBP/EACQQAAIBBAEEAgMAAAAAAAAAAAEDAgAEBRESBhMhMQcUIkFC/8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhEDEQA/AO53U9s9o4uiJe9bp7OrLRblwm0cpehWfmRveVpcIbNsGj3H+TUg+2uE5e1g97O00gdzXgboNA5Dqm2GLjCDhyZ4ANBs4RsYyupxj3DLe4mhHIWzCtaEuJmuYM5y2BrXih/J5a7tb1xYxnbA0Ik+DQCWMz9/jIFdqwcD+pDeqI7P5GyiQqL0Wr4LO4icaCKVBaHUHyqcrg/qww9qi8J/J8R7FV/c5e6utxfMSEve6j6VB//Z', 'image_url': '/file-upload/ez8vaZThSraEAtRoh/Booklet-4%20copy.png', 'image_type': 'image/png', 'image_size': 3405547, 'type': 'file'}], 'ts': datetime.datetime(2020, 4, 9, 14, 37, 13, 184000)}]}
Traceback (most recent call last):
  File "./deployments/current/manage.py", line 157, in <module>
    execute_from_command_line(sys.argv)
  File "./deployments/current/manage.py", line 122, in execute_from_command_line
    utility.execute()
  File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/management/commands/convert_rocketchat_data.py", line 45, in handle
    do_convert_data(rocketchat_data_dir=data_dir, output_dir=output_dir)
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/data_import/rocketchat.py", line 1109, in do_convert_data
    process_messages(
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/data_import/rocketchat.py", line 753, in process_messages
    raw_messages.append(message_to_dict(message))
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/data_import/rocketchat.py", line 636, in message_to_dict
    content = message["msg"]
KeyError: 'msg'

I am writing @timabbott about it.

@garg3133
Copy link
Member

garg3133 commented Nov 5, 2021

@talheim-it Okay, so it's a message with just an attachment. In that case, replacing content = message["msg"] with content = message.get("msg", "") should work fine.

@talheim-it
Copy link
Author

@garg3133 looks good. The migration runs now.

Just need to start importing.

@talheim-it
Copy link
Author

talheim-it commented Nov 5, 2021

@garg3133 now when I run the import script:

`zulip@comm01:/opt/zulip/deployments/current$ ./manage.py import "" /home/zulip/converted_rocketchat_data
Processing dump: /opt/zulip/converted_rocketchat_data ...
2021-11-05 18:59:56.614 INFO [] Importing realm dump /opt/zulip/converted_rocketchat_data
2021-11-05 18:59:56.999 INFO [] Importing realm data from /opt/zulip/converted_rocketchat_data/realm.json
Traceback (most recent call last):
  File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/lib/db.py", line 34, in execute
    return wrapper_execute(self, super().execute, query, vars)
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/lib/db.py", line 19, in wrapper_execute
    return action(sql, params)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "zerver_stream_realm_id_name_uniq"
DETAIL:  Key (realm_id, upper(name::text))=(2, name surname) already exists.


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "./manage.py", line 157, in <module>
    execute_from_command_line(sys.argv)
  File "./manage.py", line 122, in execute_from_command_line
    utility.execute()
  File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/management/commands/import.py", line 99, in handle
    realm = do_import_realm(path, subdomain, num_processes)
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/lib/import_realm.py", line 937, in do_import_realm
    bulk_import_model(data, Stream)
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/lib/import_realm.py", line 652, in bulk_import_model
    model.objects.bulk_create(model(**item) for item in data[table])
  File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/db/models/query.py", line 502, in bulk_create
    returned_columns = self._batched_insert(
  File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/db/models/query.py", line 1287, in _batched_insert
    inserted_rows.extend(self._insert(
  File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/db/models/query.py", line 1270, in _insert
    return query.get_compiler(using=using).execute_sql(returning_fields)
  File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1416, in execute_sql
    cursor.execute(sql, params)
  File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/lib/db.py", line 34, in execute
    return wrapper_execute(self, super().execute, query, vars)
  File "/opt/zulip/deployments/2021-11-04-22-20-54/zerver/lib/db.py", line 19, in wrapper_execute
    return action(sql, params)
django.db.utils.IntegrityError: duplicate key value violates unique constraint "zerver_stream_realm_id_name_uniq"
DETAIL:  Key (realm_id, upper(name::text))=(2, name surname) already exists.
`

@garg3133
Copy link
Member

garg3133 commented Nov 5, 2021

@talheim-it For me, a similar kind of error occurs when I try to import more than once from the same exported files. Can you try to delete the current export and run the migration again and then try to import the organization?

(As you've already run it for the"" subdomain, you might need to use some other subdomain this time (for ex. "test1"). Once it runs properly, you can free up the "" subdomain by running a few ./manage.py shell commands and importing the organization into the"" subdomain.

@talheim-it
Copy link
Author

@garg3133 I am checking it an come back to you in the next 30 minutes.

@talheim-it
Copy link
Author

@garg3133 I tried to reinstall zulip and updated it to the latest git version which was chat.zulip.org branch.

What I get now is:

zulip@comm01:~$ ~/deployments/current/manage.py convert_rocketchat_data /home/zulip/rocketchat --output /home/zulip/converted_rocketchat_data
Converting Data ...
Traceback (most recent call last):
  File "/home/zulip/deployments/current/manage.py", line 157, in <module>
    execute_from_command_line(sys.argv)
  File "/home/zulip/deployments/current/manage.py", line 122, in execute_from_command_line
    utility.execute()
  File "/opt/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/opt/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/opt/zulip/deployments/2021-11-05-22-15-25/zerver/management/commands/convert_rocketchat_data.py", line 45, in handle
    do_convert_data(rocketchat_data_dir=data_dir, output_dir=output_dir)
  File "/opt/zulip/deployments/2021-11-05-22-15-25/zerver/data_import/rocketchat.py", line 942, in do_convert_data
    realm = make_realm(realm_id, realm_subdomain, domain_name, rocketchat_data["instance"][0])
IndexError: list index out of range

Maybe that was added few days ago?

@garg3133
Copy link
Member

garg3133 commented Nov 5, 2021

No such change was added a few days ago. It seems that rocketchat_data["instance"] earlier contained some data but for some reason, it is just an empty list now (hence the index out of range error).

Can you print(rocketchat_data["instance"]) above this line?

@talheim-it
Copy link
Author

@garg3133 you are right:

zulip@comm01:~$ ~/deployments/current/manage.py convert_rocketchat_data /home/zulip/rocketchat --output /home/zulip/converted_rocketchat_data
Converting Data ...
[]
Traceback (most recent call last):
  File "/home/zulip/deployments/current/manage.py", line 157, in <module>
    execute_from_command_line(sys.argv)
  File "/home/zulip/deployments/current/manage.py", line 122, in execute_from_command_line
    utility.execute()
  File "/opt/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/opt/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/opt/zulip/deployments/2021-11-05-22-15-25/zerver/management/commands/convert_rocketchat_data.py", line 45, in handle
    do_convert_data(rocketchat_data_dir=data_dir, output_dir=output_dir)
  File "/opt/zulip/deployments/2021-11-05-22-15-25/zerver/data_import/rocketchat.py", line 946, in do_convert_data
    realm = make_realm(realm_id, realm_subdomain, domain_name, rocketchat_data["instance"][0])
IndexError: list index out of range

I added it above:

    print(rocketchat_data["instance"])
    realm = make_realm(realm_id, realm_subdomain, domain_name, rocketchat_data["instance"][0])

@garg3133
Copy link
Member

garg3133 commented Nov 5, 2021

In that case, you can remove the last argument from this line, making it as:

realm = make_realm(realm_id, realm_subdomain, domain_name)

and replace the make_realm function at the top with:

from django.utils.timezone import now as timezone_now

def make_realm(
    realm_id: int, realm_subdomain: str, domain_name: str
) -> ZerverFieldsT:
    created_at = float(timezone_now().timestamp())

    zerver_realm = build_zerver_realm(realm_id, realm_subdomain, created_at, "Rocket.Chat")
    realm = build_realm(zerver_realm, realm_id, domain_name)

    # We may override these later.
    realm["zerver_defaultstream"] = []

    return realm

But I don't understand where did the data go when it was present before? (The data in rocketchat_data["instance"] comes from the instances.bson file.)

@talheim-it
Copy link
Author

@garg3133 I made a new dump and then it happened when I downloaded the chat.zulip.org branch for v5 dev.

I didn't check the bson files further.

@talheim-it
Copy link
Author

talheim-it commented Nov 5, 2021

@garg3133 okay the data_migration ran without issues right now.

Issues stays the same:
django.db.utils.IntegrityError: duplicate key value violates unique constraint "zerver_stream_realm_id_name_uniq"

The problem is that we talk about livechannels. It seems that because of a live channel I ran into this issue:

Traceback (most recent call last):
  File "/opt/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/opt/zulip/deployments/2021-11-05-22-15-25/zerver/lib/db.py", line 34, in execute
    return wrapper_execute(self, super().execute, query, vars)
  File "/opt/zulip/deployments/2021-11-05-22-15-25/zerver/lib/db.py", line 19, in wrapper_execute
    return action(sql, params)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "zerver_stream_realm_id_name_uniq"
DETAIL:  Key (realm_id, upper(name::text))=(3, USER NAME) already exists.

I am not really sure if it makes sense to keep the omnichannel/livechannel chats or just drop it out by migration since zulip is not having something like this.

From the realm.json:

    {
      "id": 6,
      "name": "USER NAME",
      "date_created": 1580568227.221,
      "deactivated": true,
      "description": "",
      "rendered_description": "",
      "recipient": null,
      "invite_only": false,
      "history_public_to_subscribers": false,
      "is_web_public": false,
      "stream_post_policy": 1,
      "is_in_zephyr_realm": false,
      "email_token": "e614673e59bea9b546babfe0d6f9e4b6",
      "message_retention_days": null,
      "first_message_id": null,
      "realm": 0
    },

    {
      "id": 14,
      "name": "USER NAME,
      "date_created": 1584209095.592,
      "deactivated": true,
      "description": "",
      "rendered_description": "",
      "recipient": null,
      "invite_only": false,
      "history_public_to_subscribers": false,
      "is_web_public": false,
      "stream_post_policy": 1,
      "is_in_zephyr_realm": false,
      "email_token": "195561f315db62c02b27610fa08ad6df",
      "message_retention_days": null,
      "first_message_id": null,
      "realm": 0
    },

    {
      "id": 52,
      "name": "USER NAME",
      "date_created": 1577536010.516,
      "deactivated": true,
      "description": "",
      "rendered_description": "",
      "recipient": null,
      "invite_only": false,
      "history_public_to_subscribers": false,
      "is_web_public": false,
      "stream_post_policy": 1,
      "is_in_zephyr_realm": false,
      "email_token": "c5c5ae9ceecd2f7c261e4931aed48a71",
      "message_retention_days": null,
      "first_message_id": null,
      "realm": 0
    },

I have one user very often in it, can that be the reason why it is not working?

@talheim-it
Copy link
Author

If I see it right it is because the names of the LiveChat user are the ids of the user and so we produce duplications.

@garg3133
Copy link
Member

garg3133 commented Nov 5, 2021

Yes, you are right. This error seems to be caused by the duplication of LiveChat channel names, which when converted to Zulip streams create duplicate stream names (no two streams in Zulip can have the same name).

As a temporary solution, you can edit the realm.json file and change the names of duplicate streams. It should get imported correctly after that.

Ideally, all the livechat channels should be converted to topics in a single Zulip stream, but that is yet to be developed in this tool.

@talheim-it
Copy link
Author

talheim-it commented Nov 5, 2021

@garg3133 I would prefer to drop the livechat since it is completely useless to import the communication into Zulip. I see no benefit on it since it is for communication with customers from website etc.

I sit over an hour to fix duplications, that is a real waste of time if there is no clear reason to import it.

Anyway I am running into the next issue by importing:

zulip@comm01:/opt/zulip/deployments/current$ ./manage.py import "test1" /home/zulip/converted_rocketchat_data
Processing dump: /opt/zulip/converted_rocketchat_data ...
2021-11-05 23:29:17.515 INFO [] Importing realm dump /opt/zulip/converted_rocketchat_data
2021-11-05 23:29:17.517 INFO [] Importing realm data from /opt/zulip/converted_rocketchat_data/realm.json
2021-11-05 23:29:17.791 INFO [] Successfully imported <class 'zerver.models.Stream'> from zerver_stream.
2021-11-05 23:29:18.659 INFO [] Successfully imported <class 'zerver.models.DefaultStream'> from zerver_defaultstream.
2021-11-05 23:29:18.660 INFO [] Successfully imported <class 'zerver.models.RealmEmoji'> from zerver_realmemoji.
2021-11-05 23:29:18.662 INFO [] Successfully imported <class 'zerver.models.RealmDomain'> from zerver_realmdomain.
2021-11-05 23:29:18.663 INFO [] Successfully imported <class 'zerver.models.RealmFilter'> from zerver_realmfilter.
2021-11-05 23:29:18.664 INFO [] Successfully imported <class 'zerver.models.RealmPlayground'> from zerver_realmplayground.
2021-11-05 23:29:18.680 INFO [] Successfully imported <class 'zerver.models.Recipient'> from zerver_recipient.
2021-11-05 23:29:18.944 INFO [] Successfully imported <class 'zerver.models.Subscription'> from zerver_subscription.
2021-11-05 23:29:18.945 INFO [] about to call create_subscription_events
2021-11-05 23:29:19.086 INFO [] done with create_subscription_events
2021-11-05 23:29:19.092 INFO [] Successfully imported <class 'zerver.models.Huddle'> from zerver_huddle.
2021-11-05 23:29:19.100 INFO [] Successfully imported <class 'zerver.models.UserPresence'> from zerver_userpresence.
2021-11-05 23:29:19.101 INFO [] Successfully imported <class 'zerver.models.UserActivity'> from zerver_useractivity.
2021-11-05 23:29:19.102 INFO [] Successfully imported <class 'zerver.models.UserActivityInterval'> from zerver_useractivityinterval.
2021-11-05 23:29:19.103 INFO [] Successfully imported <class 'zerver.models.CustomProfileField'> from zerver_customprofilefield.
2021-11-05 23:29:19.104 INFO [] Successfully imported <class 'zerver.models.CustomProfileFieldValue'> from zerver_customprofilefieldvalue.
2021-11-05 23:29:19.105 INFO [] Importing avatars
2021-11-05 23:29:19.133 INFO [] Importing uploaded files
2021-11-05 23:29:31.614 INFO [] Processed 1000/2948 uploads
2021-11-05 23:29:37.229 INFO [] Processed 2000/2948 uploads
2021-11-05 23:29:40.282 INFO [] Importing emojis
2021-11-05 23:29:40.293 INFO [] Importing message dump /opt/zulip/converted_rocketchat_data/messages-000001.json
2021-11-05 23:29:40.798 WARN [] Error in Markdown rendering for message ID 131963; continuing
2021-11-05 23:29:40.800 WARN [] Error in Markdown rendering for message ID 176241; continuing
2021-11-05 23:29:40.803 WARN [] Error in Markdown rendering for message ID 133488; continuing
2021-11-05 23:29:40.879 WARN [] Error in Markdown rendering for message ID 159566; continuing
2021-11-05 23:29:40.940 WARN [] Error in Markdown rendering for message ID 130161; continuing
2021-11-05 23:29:40.942 WARN [] Error in Markdown rendering for message ID 129803; continuing
2021-11-05 23:29:40.955 WARN [] Error in Markdown rendering for message ID 131121; continuing
2021-11-05 23:29:40.959 WARN [] Error in Markdown rendering for message ID 132552; continuing
2021-11-05 23:29:41.022 WARN [] Error in Markdown rendering for message ID 129981; continuing
2021-11-05 23:29:41.038 WARN [] Error in Markdown rendering for message ID 135464; continuing
2021-11-05 23:29:41.049 WARN [] Error in Markdown rendering for message ID 178505; continuing
2021-11-05 23:29:41.164 WARN [] Error in Markdown rendering for message ID 136224; continuing
2021-11-05 23:29:41.236 WARN [] Error in Markdown rendering for message ID 135660; continuing
2021-11-05 23:29:41.246 WARN [] Error in Markdown rendering for message ID 131016; continuing
2021-11-05 23:29:41.250 WARN [] Error in Markdown rendering for message ID 130530; continuing
2021-11-05 23:29:41.352 WARN [] Error in Markdown rendering for message ID 131129; continuing
2021-11-05 23:29:41.366 WARN [] Error in Markdown rendering for message ID 129860; continuing
2021-11-05 23:29:41.377 WARN [] Error in Markdown rendering for message ID 130142; continuing
2021-11-05 23:29:41.392 WARN [] Error in Markdown rendering for message ID 134445; continuing
2021-11-05 23:29:41.394 WARN [] Error in Markdown rendering for message ID 142866; continuing
2021-11-05 23:29:41.410 WARN [] Error in Markdown rendering for message ID 161282; continuing
2021-11-05 23:29:41.437 WARN [] Error in Markdown rendering for message ID 132387; continuing
2021-11-05 23:29:41.466 WARN [] Error in Markdown rendering for message ID 171387; continuing
2021-11-05 23:29:41.468 WARN [] Error in Markdown rendering for message ID 131023; continuing
2021-11-05 23:29:41.517 WARN [] Error in Markdown rendering for message ID 150414; continuing
2021-11-05 23:29:41.538 WARN [] Error in Markdown rendering for message ID 134442; continuing
2021-11-05 23:29:41.548 WARN [] Error in Markdown rendering for message ID 170400; continuing
2021-11-05 23:29:41.614 WARN [] Error in Markdown rendering for message ID 147965; continuing
2021-11-05 23:29:41.617 WARN [] Error in Markdown rendering for message ID 178297; continuing
2021-11-05 23:29:41.658 WARN [] Error in Markdown rendering for message ID 136502; continuing
2021-11-05 23:29:41.705 WARN [] Error in Markdown rendering for message ID 177170; continuing
2021-11-05 23:29:41.713 WARN [] Error in Markdown rendering for message ID 180309; continuing
2021-11-05 23:29:41.717 WARN [] Error in Markdown rendering for message ID 132402; continuing
2021-11-05 23:29:41.722 WARN [] Error in Markdown rendering for message ID 156257; continuing
2021-11-05 23:29:41.754 WARN [] Error in Markdown rendering for message ID 147955; continuing
2021-11-05 23:29:41.844 WARN [] Error in Markdown rendering for message ID 131139; continuing
2021-11-05 23:29:41.878 WARN [] Error in Markdown rendering for message ID 171426; continuing
2021-11-05 23:29:41.898 WARN [] Error in Markdown rendering for message ID 159962; continuing
2021-11-05 23:29:41.909 INFO [] Successfully rendered Markdown for message batch
Traceback (most recent call last):
  File "/opt/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 242, in _commit
    return self.connection.commit()
psycopg2.errors.ForeignKeyViolation: insert or update on table "zerver_message" violates foreign key constraint "zerver_message_sender_id_77b89151_fk_zerver_userprofile_id"
DETAIL:  Key (sender_id)=(80) is not present in table "zerver_userprofile".


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "./manage.py", line 157, in <module>
    execute_from_command_line(sys.argv)
  File "./manage.py", line 122, in execute_from_command_line
    utility.execute()
  File "/opt/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/opt/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/opt/zulip/deployments/2021-11-05-22-15-25/zerver/management/commands/import.py", line 99, in handle
    realm = do_import_realm(path, subdomain, num_processes)
  File "/opt/zulip/deployments/2021-11-05-22-15-25/zerver/lib/import_realm.py", line 1227, in do_import_realm
    import_message_data(realm=realm, sender_map=sender_map, import_dir=import_dir)
  File "/opt/zulip/deployments/2021-11-05-22-15-25/zerver/lib/import_realm.py", line 1412, in import_message_data
    bulk_import_model(data, Message)
  File "/opt/zulip/deployments/2021-11-05-22-15-25/zerver/lib/import_realm.py", line 652, in bulk_import_model
    model.objects.bulk_create(model(**item) for item in data[table])
  File "/opt/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/opt/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/db/models/query.py", line 523, in bulk_create
    obj_without_pk._state.db = self.db
  File "/opt/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/db/transaction.py", line 246, in __exit__
    connection.commit()
  File "/opt/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 33, in inner
    return func(*args, **kwargs)
  File "/opt/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 266, in commit
    self._commit()
  File "/opt/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 242, in _commit
    return self.connection.commit()
  File "/opt/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/opt/srv/zulip-venv-cache/4293996ea9b81a02690e78a21ea2f1f0bc2e6597/zulip-py3-venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 242, in _commit
    return self.connection.commit()
django.db.utils.IntegrityError: insert or update on table "zerver_message" violates foreign key constraint "zerver_message_sender_id_77b89151_fk_zerver_userprofile_id"
DETAIL:  Key (sender_id)=(80) is not present in table "zerver_userprofile".

When I look into the realm.json file I see no user with the id 80 in zerver_userprofile

@talheim-it
Copy link
Author

@staffcop @garg3133 worked with me on my server, we made the live chat optional. As soon as it is merged you can try it :)

Here is all working now. Great job @garg3133

garg3133 added a commit to garg3133/zulip that referenced this issue Nov 7, 2021
This resolves the issues reported in zulip#20108, major chunk of which were
due to the incomplete support for importing the livechat streams/messages
in the tool. So, it's best not to import any livechat streams/messages for
now until a complete support for importing the same is developed.
timabbott pushed a commit that referenced this issue Nov 7, 2021
This resolves the issues reported in #20108, major chunk of which were
due to the incomplete support for importing the livechat streams/messages
in the tool. So, it's best not to import any livechat streams/messages for
now until a complete support for importing the same is developed.
garg3133 added a commit to garg3133/zulip that referenced this issue Nov 7, 2021
…t tool.

This commit fixes the rest of the issues reported in zulip#20108, first set of
which were fixed in zulip#20195.

Closes: zulip#20108
@garg3133
Copy link
Member

garg3133 commented Nov 7, 2021

#20195 and #20196 addresses all the issues reported here.

danielpyon pushed a commit to danielpyon/zulip that referenced this issue Dec 1, 2021
This resolves the issues reported in zulip#20108, major chunk of which were
due to the incomplete support for importing the livechat streams/messages
in the tool. So, it's best not to import any livechat streams/messages for
now until a complete support for importing the same is developed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants