Specify7 Login error for one user

Hi everyone, we are testing Specify7 and so far all ok, minus an issue with one of the users when he tries to login, see error below:

Looks like the error relates to something returning more than one agent (see highlighted area)? This Db works fine on Specify 6.8.03

I wonder if this is related to Cannot set batch of agents for collection access · Issue #2405 · specify/specify7 · GitHub? Not quite the same error message but, this error is stating multiple agents returned, which would seem similar to MultipleAgentsException.

Is the agent linked to this user used across disciplines or divisions?

Hi Mark, interesting, the issue happens when the user logs in, then selects a collection. The user is linked to all collections. But also the rest of the users… So only one user is having the issue.

Hi @ray and @markp,

While the issue may be directly related to Cannot set batch of agents for collection access · Issue #2405 · specify/specify7 · GitHub, I have looked a little further into this I don’t think it is the case.

Can you ensure there are no Agents in the same Division which are associated with more than one SpecifyUser?

An easy way to accomplish this in the application is to log in to a Collection with a SpecifyUser which is functional and run the following Query, using Agent as the base table (You may need to check Reveal Hidden Form Fields in the bottom left of the Query to see the SpecifyUser relationship in the list of queryable fields)

You can further refine the Query as needed, such as restricting the SpecifyUser name to that of the affected user.

In the results, you would be looking for Agents which have the same Specifyuser. In this example, we see that Agent B and Agent C are both associated with User B.

Alternatively, this can be accomplished via the API by navigating to http://<DOMAIN>/api/specify/agent/?specifyuser__name__contains=USERNAME after replacing <DOMAIN> with your instances domain and USERNAME with part of or all of the name of the Specifyuser. The returned JSON format are Agent objects which are associated with Specifyusers which have the name USERNAME.

Or through SQL by running the following Query: select ag.specifyuserid, name, agentid, lastname, divisionid from agent ag join specifyuser sp on ag.specifyuserid=sp.specifyuserid;

Please let me know if you have any additional questions with the instructions provided above.

We can continue with solutions if that is truly the case and you were able to find that more than one Agent is associated with the SpecifyUser in question, otherwise we may need additional information (such as the Crash Report) which can be sent via E-mail if you wish.

In the interim, I have created an Issue on GitHub to track this problem: MultipleObjectsReturned get() returned more than one Agent crash on login · Issue #4382 · specify/specify7 · GitHub

Hi Jason, it seems that is the issue, what would be the best way to fix something like this? I can see both have the same email address, is that how they are attached to each other?

Also, would fixing this cause any issues with Specify6? (we are looking at the possibility of running both 7 and 6 for a short period of time while we completely move to 7.

Thank you for the quick response!

Thankfully, resolving this issue should not cause any problems with Specify 6.

I can see both have the same email address, is that how they are attached to each other?

Besides directly using SQL in the database to set the relationship, I am unsure how the application can be used to associate multiple agents to one Specifyuser. It does not seem possible in recent versions of Specify 7, and further investigation will be performed to determine if it is possible in earlier versions of Specify 7 and Specify 6.

Also, It appears the two Agent records referencing the Specifyuser might be duplicates if they have the same email and the same name.
Can confirm that these two Agent records are duplicates and meant to reference the same person? Or are these two Agent records meant to be distinct and separate?

If these Agent records are duplicates and you are using Specify v7.9.0 or later, you can utilize the Record Merging tool to merge them into a single Agent record.

Regardless, the solution will be to disconnect one of the Agents from the Specifyuser.

Through Specify7, this can be done through the Security and Accounts Panel by unsetting and then resetting the Agent on the Specifyuser.

Below is an attached video following my example from before.
I have decided that the Specifyuser User B should be associated with Agent B

After saving the Specifyuser, the error should no longer occur whenever the affected Specifyuser logs in.

If you are unsure which Agent to use, I would recommend querying on the Audit Log table and comparing the entries of each Agent.
The audit log can be queried by navigating to http://<DOMAIN>/specify/query/new/spauditlog/ and constructing a query like the one below.

I would suggest the Agent that has a greater presence in the database be selected.

Technically, the purpose of the assigning an Agent to a Specifyuser is to record the ModifiedByAgent and CreatedByAgent for every record as the User creates/updates/deletes records.
If there are two Agents assigned to a single Specifyuser, then Specify would not know which Agent to put down as having Modified or Created the records.

Let me know if you have any further questions.

Hi Jason, than you for the reply, I will go ahead and try your suggestions.

Funny thing happened, the DB disappeared, had to be rebuild again, using the all-in-one dockerized version, have you seen anything like that happened before?

In any case, I will try what you suggested and reply back after, thank you again.

Hi @jason_m , I followed the instructions to merge agents, but it’s been a day already and nothing is happening… any idea?

Hi @ray,

Have you tried to refresh the page? Do you see a notification (after clicking on the :bell_: Notifications button in the navigation menu) letting you know that the merge has succeeded or failed?

Hi, I can see the notification, but it only says “The merge process has started”, is there a log that I can look into to see what errors are happening?

Hi @ray,

You can see the status of current and past record merging activity in the spmerging table in the database.

You would then want to make sure the Specify 7 Worker is running. This is the component that runs separate from the main Specify 7 instance that handles WorkBench and record merging operations. If this is not running, an agent merge can never begin as it is a dependency for that process.

Can you verify the worker process is running and let me know if you are still having an issue?

Hi, I’m a little confused, I’m using the dockerized version of Specify7, the one called (just-specify7), does this not already have the worker? If not, where are the install instructions? Could not find anything related to that, thank you.

This does have the worker built-in! In the docker-compose.yml, this uses a set of environment variables that should be identical to the specify7-service ones.

You may need to restart the specify7-worker process in Docker. Use docker ps to find the container ID and then use docker restart {container ID}. After that, you can try the merge again!

That was it! the worker was not running… Thank you for all the help.

Now, back to original question, I was able to merge some duplicate agents, but, there is one that is not allowing me to do so, i get an error, see below:

(receiver, receiver(signal=self, sender=sender, **named))\n File "/opt/specify7/specifyweb/businessrules/orm_signal_handler.py", line 15, in handler\n rule(kwargs[‘instance’])\n File "/opt/specify7/specifyweb/businessrules/agent_rules.py", line 11, in agent_delete_blocked_by_related_specifyuser\n raise BusinessRuleException(\nspecifyweb.businessrules.exceptions.BusinessRuleException: (‘agent cannot be deleted while associated with a specifyuser’, {‘table’: ‘Agent’, ‘fieldName’: ‘specifyuser’, ‘agentid’: 4130, ‘specifyuserid’: 2})\n",

Any ideas?

The issue contained in that excerpt indicates the following:

agent cannot be deleted while associated with a specifyuser

Can you confirm that one of the agents being merged is already associated with a Specify user?

Hi, well they are. but isn’t the merge feature supposed to fix that? is there another step I need to take to fix this?

Can you try to perform the merge using that user’s Specify account? There is some “behind-the-scenes” logic that selects the ‘primary’ agent in a merge, and if the agent associated with a user is not the ‘primary’ in the merge, the error you encountered will occur.

You can also try selecting the agents you wish to merge in a different order so that the one associated with a Specify user will be used as the ‘primary’ agent in the merge.

Well, I can’t login using that user’s credentials, i get an error… That’s why I created this post, also, I tried your suggestion about the order of the agents on the merge and was a no go. Any other ideas?

Could you try the second idea mentioned here? (through Security and Accounts)