Anonymous users cannot export CSVs

Specify v7.9.6.1

On the OSU production instance at invertebrates.osu.edu, the anonymous user (testuser) cannot export query results as a .csv.
This does not seem to be the same issue as Export to CSV does not notify the user, because the .csv is never created. Even when reloading the page multiple times and navigating to other pages, trying the export again, etc.

When signed in as any other user with the same permissions as the anonymous user, query results can be exported.

On the back end, we get this error when anonymous users press the ‘Create CSV’ button:

Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/opt/specify7/specifyweb/stored_queries/execution.py", line 153, in do_export
    field_specs = field_specs_from_json(spquery['fields'])
  File "/opt/specify7/specifyweb/stored_queries/execution.py", line 134, in field_specs_from_json
    for data in sorted(json_fields, key=lambda field: field['position'])]
  File "/opt/specify7/specifyweb/stored_queries/execution.py", line 134, in <lambda>
    for data in sorted(json_fields, key=lambda field: field['position'])]
KeyError: 'position'

Steps to reproduce:

  • Navigate to Sp7 instance with anonymous user configured
  • Run any query
  • Click ‘Create CSV’

Hi @nfshoobs

I am able to export a query for CollectionObjects between the range of 000000001 and 000000005 without error. Is there a particular query (or set of queries) that are failing? It may have something to do with the tables or fields used.

Best,
Mark

@markp I’m having weirdly inconsistent results. I’ve tried it with the stock queries from the taxon tiles, and also using query https://invertebrates.osu.edu/specify/query/93/ .
Over the last two hours, some of the time I’ve been able to export, and other times not.
We rebuilt our docker container and pulled the updates that were pushed today (having last updated 4 months ago) and that seemed to have fixed the issue at first, but I haven’t been able to get it to generate an export as the anon user on my end for the last hour.

It may be a problem with our server infrastructure and not a specify problem. Our IT is looking into it.

Hi @nfshoobs,

This is entirely my opinion and unsolicited advice, but I would avoid pulling from a commit and using in production (based on the version information it looks like you are now running e1e47642f98ffc3e7e54c6cba50f79c3d38f9b2e) , it may cause you some additional headaches. Instead, you can pull from the latest tagged release, which would be 7.9.6.2. It also helps both others and the Specify team with debugging issues.

The Specify team may outline additional required steps or breaking changes in the release notes for a given release, and directly pulling from a commit skips over that.

If you are using docker, you can use v7 as the tag, to pull the latest tagged release.

1 Like

Hey @markp, this was something our IT staff suggested when we ran into problems, so I’ll relay the message to them that it’s best to only do the tagged releases.
RE the issue that spawned this topic, it appears to have been transient. I thought for sure it must have been a permissions issue (due to the fact that only the anonymous user was unable to generate reports) but since it fixed itself without my updating permissions, I’m still in the dark as to why it happens.

update: I am pretty certain that this actually has to do with the issue of multiple users concurrently viewing a collection page as an anonymous user. Today I was doing a demo of our DB for other staff in the division and we ran into the error again (with all 3 of us on separate computers looking at the same query). We were only able to generate a .csv when we had all closed all browser tabs on all machines, and reopened, requested the file, and refreshed on ONE machine.