Just to add to this, I've done some further testing and can confirm a few
more bits about the inconsistency.
Firstly the behaviour is not browser-specific, occurring in both firefox
and chrome.
Secondly it seems to fail always when running web2py normally. When running
in the debugger in pycharm it *sometimes* works, and sometimes fails in
precisely the same manner. I am somewhat at my wits end.
My only thoughts are either a caching issue or a race condition, but I
can't see any immediate reason for either of these. Even when starting with
a fresh session we seem to see this behaviour...
On Tuesday, 26 March 2019 11:50:06 UTC, Francis Windram wrote:
>
> Hi All,
>
> I'm having a very very weird problem with some upload processing I'm
> performing in web2py.
> Firstly for context here is the code I am using:
>
> Controller:
> def validate_test():
> form = SQLFORM.factory(
> Field('csvfile', 'upload'), table_name="dataset_upload")
> if form.validate():
> logger.info("form validating")
> candidate_file = request.vars.csvfile.file.read()
> logger.info("{}".format(candidate_file))
> elif form.process().accepted:
> response.flash = 'form accepted'
> elif form.errors:
> response.flash = 'form has errors'
> return dict(form=form)
>
>
> And the View:
> {{extend 'layout.html'}}
>
> <div style="background: linear-gradient(240deg, lightgrey, whitesmoke)"
> class="jumbotron">
> <br><br>
> {{=form}}
> </div>
>
> This is essentially as simple as it can be. The user should upload a csv
> file, and I wish to run a suite of validators on that csv file before
> returning to the user whether the validation was passed or where it failed
> and on what.
>
> Now this is the first step, just checking that the form csv is readable by
> the server. And here is where I hit the problem:
> Sometimes I get out (as expected) the contents of the csv file from logger
> .info("{}".format(candidate_file))
> Most of the time I just get out a blank string, even with the same input
> file!
>
> I feel like I'm going mad, doing the same thing twice and getting
> different results. It smells to me like caching or race conditions but I
> just have no idea what really is going on or why this might be happening.
>
> Do you have any ideas?
>
> Thanks!
>
> P.S. also more generally is this a good way to perform validation on a csv
> file without any database IO? I want users to be able to check whether
> their file fits the canonical format prior to actually attempting to commit
> it to the database?
> It would be nice to be able to use the Web2Py validators to do this
> validation, but I don't really want to start creating temporary staging
> tables to perform this validation prior to upload, especially as I have a
> multi-table structure which the data will be going in to, but it comes in
> as a flat csv.
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.