Comments (5)
In this case (juanpsenn@5645421) I'm testing validating an older receipt (older than the last successfully validated receipt), this should fail but also raises an exception when it shouldn't.
Thanks for a clear test case. It should not raise an exception in this case; it would make sense to handle this case properly.
An unusual thing about this is that we don't have "one error per receipt" like in other scenarios, just one error for the whole batch.
I remember this #31 (comment) and I think that validate() can easily be transactional. Otherwise, this causes integrity issues in the database if the transaction is not handled outside.
Yup. I initially though about documenting that a transaction should be started, but handling the transaction inside validate
is probably safer.
Why errors are handled differently?
Generally when a receipt is valid, AFIP returns a response with a "success result". When it's somehow invalid, it returns a response with a "Failure result". If you send two receipts, you might get one "success result" and one "failure result".
But for this particular case, it does not return that, but returns an error instead (which is a completely different structure). The error is in a format very similar to the "invalid authentication ticket" kind of error. check_response
looks for any error of this style and raises (because if authentication fails we do raise). Failure results are handled inside Receipt._validate
.
If you want to use REST as an analogy, think of this as "returning HTTP 200 with a JSON describing a failure" vs returning HTTP 400.
Note that in this case, all receipts are rejected; there's no partial successes.
Should validate() be transactional itself?
Yes. ReceiptQuerySet.validate
should run transactional.
from django-afip.
Thinking about this further, I think we should drop the raise_
parameter for validate()
, and never raise (e.g.: keep the behaviour of raise_=False
. Raising in this case is a poor interface.
from django-afip.
from django-afip.
From import this
:
Errors should never pass silently.
Unless explicitly silenced.
We really should raise an exception for any error. Returning a list of errors is a terrible API. In future Python versions, we can use exception groups.
from django-afip.
Obviously this needs documented as a very breaking change in the changelog.
from django-afip.
Related Issues (20)
- Tutorial de renovación de certificados HOT 3
- Error en el formulario de TaxPayer en referencia a certificate HOT 6
- Validations with cae expiration `31 de diciembre de 1969 a las 21:00` HOT 1
- Factura E
- Se pueden generar: Factura de Crédito electrónica MiPyMEs (FCE) A? HOT 9
- Se subio el changelog 11.2.0? HOT 3
- Crash with urllib3 >= 2.0.0
- Error al momento de registrar una Nota de Crédito electrónica MiPyMEs (FCE) A HOT 20
- Integrate with django's custom file storage settings HOT 1
- CI jobs with MySQL are broken.
- Duda respecto al campo quantity en ReceiptEntry HOT 7
- Generación de PDF con múltiples paginas HOT 14
- Use an SVG-based QR code
- Use snapshots for PDF/HTML generation tests
- error 10048 afip monotributo
- Investigate failing CI tasks
- Live tests fail HOT 8
- Problema al obtener los puntos de ventas o al validad un Comprobante HOT 3
- Codigo ejemplo HOT 1
- Consider dropping ReceiptValidation.RESULT_REJECTED
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-afip.