Forums

The field was updated in the table but the APP shows the old value.

deleted
I will make more tests.

I thought the error occurred because I was using GLOBAL. So I stored the variables in a table, but the error persists. After the trat field has been updated, Workbench shows that it has indeed been updated. However, when calling the data through the APP, all fields are ok, except the trat field, which remains with the old value.

It is not memory residue on the computer where the change was made by the APP because the same happens searching for data through the APP on any computer. How can the table show one value and another appears in the APP?

The error occurs in 50 to 60% of changes. The same error occurs when changing the field through Workbench.

def consultaPOST(PacFilaConsulta, PmovConsulta, request):

PacHoje = Pac.objects.get(numpac = PacFilaConsulta.numpac) PesquisaUltimaConsulta = PmovConsulta.order_by('-data')

trat = request.POST['Trat']

id_variaveis = Variaveis.objects.all()[0].id if Variaveis.objects.get(id = id_variaveis).MM_printed == "": PacHoje.trat = trat else: PacHoje.trat = "MM" # In this case the field on table is updated # but when requested by APP the old value is showed # It occurs in any computer

PacHoje.lado = str(request.POST['lado']).strip() PacHoje.pd = Decimal(request.POST['Pd']) PacHoje.medico = PacFilaConsulta.medico

if PesquisaUltimaConsulta.exists() and PesquisaUltimaConsulta[0].data.date() == date.today(): PmovHoje = PesquisaUltimaConsulta[0] else: PmovHoje = Pmov()

PmovHoje.numpac = PacFilaConsulta.numpac PmovHoje.lado = str(request.POST['lado']).strip() PmovHoje.trat = request.POST['Trat'] PmovHoje.medico = PacFilaConsulta.medico

PacFilaConsulta.lado = str(request.POST['lado']).strip() PacFilaConsulta.pd = Decimal(request.POST['Pd']) PacFilaConsulta.metade = Decimal(request.POST['Metade']) PacFilaConsulta.sala = "S"

try: FormPmov = PmovForm(instance = PmovHoje) FormPmov.cleaned_data = FormPmov FormPmov.save()

FormPac = PacForm(instance = PacHoje)
FormPac.cleaned_data = FormPac
FormPac.save()

FormFila = FilaForm(instance = PacFilaConsulta)
FormFila.cleaned_data = FormFila
FormFila.save()

except Exception as xxx: # Everything goes without errors. All fields are updated # The Workbench shows that the trat field has been changed to MM # But the APP shows the trat field with the old value

return consultaGET(PacFilaConsulta, PmovConsulta, request)

If your code is showing a different value to what is in the database, then you may have something that is keeping the value between requests (like a global or module-level variable). Check the code that shows the value.

Thanks. I will try to eliminate all GLOBAL. I found the error. When reviewing GLOBAL I found a bug in the code.

Glad you were able to solve it.

Global works fine on localhost but not on WEB SERVERS.

Suggestion: You could send a notice to all users of pythonanywhere.com to also have an account on eu.pythonanywhere.com (and vice versa) - It will serve for testing and also as a second option if the first one becomes inoperative or the APP presents any problem. - I didn't realize this until the day pythonanywhere.com was down for about 3 hours. I decided that for security I should have another Web Server. That's when I asked you and you suggested creating another account at eu.pythonanywhere.com. It was a great suggestion because this way I can carry out tests at will, without the stress of making a mistake and my APP becoming inoperative. What's more: it's the same platform (which makes it a lot easier). - I believe that if everyone is aware, you will greatly increase the number of users. Thanks.

Happy to hear that this solution works for you! And thanks for the suggestion, we'll consider that.