HTTP Status 500 - Request processing failed Incorrect result size: expected 1, actual 0 - spring-jdbc

exception is org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0] with root cause
org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0

Related

How can I tell mypy that a condition is guaranteed?

My actual case is more complicated, but the MVCE is
from typing import List
def find_largest(numbers: List[int]) -> List[int]:
"""
>>> find_largest([3, 4, 5, 5, 3, 1, -2, 4, 3, 3])
[5, 5]
"""
assert len(numbers) > 0 # guaranteed by caller
largest_numbers = None
value = None
for number in numbers:
if value is None or number > value:
largest_numbers = [number]
value = number
elif number == value:
largest_numbers.append(number)
return largest_numbers
if __name__ == '__main__':
import doctest
doctest.testmod()
When I run mypy on this, I get:
mytest.py:18: error: Incompatible return value type (got "Optional[List[int]]", expected "List[int]")
Found 1 error in 1 file (checked 1 source file)
But restrictions which are not captured by mypy guarantee that None is not returned. How can I hint that to mypy? (Initializing with something else is NOT possible)
Your code can still return None according to Mypy and the it thinks the typing is correct.
Assuming you can't fix this you could also force the return to always have a value with:
assert largest_numbers
return largest_numbers
Alternatively, use typing.cast:
To the type checker this signals that the return value has the designated type, but at runtime we intentionally don’t check anything (we want this to be as fast as possible).
from typing import List, cast
...
def find_largest(numbers: List[int]) -> List[int]:
"""
>>> find_largest([3, 4, 5, 5, 3, 1, -2, 4, 3, 3])
[5, 5]
"""
assert len(numbers) > 0 # guaranteed by caller
largest_numbers = None
value = None
for number in numbers:
if value is None or number > value:
largest_numbers = [number]
value = number
elif number == value:
largest_numbers.append(number)
return cast(List[int], largest_numbers)
...

Make R stopifnot or similar simple function raise an error when expression returns length of zero

I'm using the stopifnot function in R to validate an expected result. However, I've noticed that if the expression returns a vector of length 0, then stopifnot will not raise an error. Here is a simple reproducible example.
Imagine an optimization function where one of the list elements is named convergence containing either a 0 or 1, and I wish to validate that the element named convergence contains 0 and raise an error otherwise.
return01 <- function(x){
return(list(convergence = x))
}
opt1 <- return01(1)
I can easily do the validation I desire with stopifnot.
stopifnot(opt1$convergence == 0) # raises desired error
However, imagine I typed the wrong element name such as converged instead of convergence. My validation no longer throws any error because opt1$converged is NULL and opt1$converged == 0 resolves to logical(0)
stopifnot(opt1$converged == 0) # does not raise an error
stopifnot(NULL == 0) # does not raise an error
I've come up the workaround below where I would always have to also validate the length of the expression as well.
stopifnot(opt1$converged == 0, length(opt1$converged == 0) > 0) # raises an error
stopifnot(NULL == 0, length(NULL == 0) > 0) # raises an error
Is there a simpler, more elegant, or better practice solution here to make this validation robust to the expression returning logical(0) yet retaining the simplicity and conciseness of stopifnot(opt1$convergence == 0) rather than having to explicitly do another expression using length? Specifically, I would like the validation to also raise an error if the expression returns logical(0).
Check whether it is identical to zero:
stopifnot(identical(opt1$convergence, 0))
or if convergence is normally of integer type use 0L.
The code above will raise an error if convergence is anything other than 0. For example,
stopifnot(identical(1, 0))
## Error: identical(1, 0) is not TRUE
stopifnot(identical(NULL, 0))
## Error: identical(NULL, 0) is not TRUE
stopifnot(identical(numeric(0), 0)
## Error: identical(numeric(0), 0) is not TRUE
stopifnot(identical(logical(0), 0))
## Error: identical(logical(0), 0) is not TRUE

Data Buffer Exceeded error while connecting BW Cube

I am reading data from BW Cube with the following code
actual <- RSAPReadCube(conn, 'ZAPO_C17', chars=list('ZBEGINV', 'ZKF339', 'ZTOTJFF', 'ZOPENPL6', 'ZDLV_QTY', 'ZBACKLOG2'), kfigures=list('ZBEGINV', 'ZKF339', 'ZTOTJFF', 'ZOPENPL6', 'ZDLV_QTY', 'ZBACKLOG2'))
I am getting following error:
Error: Problem Invoking RFC (RSDPL_CUBE_DATA_READ): 5 / INHERITED_ERROR / ID:RS_EXCEPTION Type:E Number:000 Subfield access (offset = 0, length = 1-) to adata object of size 30 outside valid limits
Please help
Resolved with correct argument - which has Characteristic Technical Name
actual <- RSAPReadCube(conn, 'ZAPO_C17', chars=list('0MATERIAL', 'ZBWSDVERS'), kfigures=list('ZBEGINV', 'ZKF339', 'ZTOTJFF', 'ZOPENPL6', 'ZDLV_QTY', 'ZBACKLOG2'))

how to config CNMI to receive delivary message?

I have a d-link gsm modem (DWM-156) and i want to config CNMI to receive delivery reports after sending a text message.
The support CNMI mode on my modem returns:
+CNMI: (0-3), (0-3), (0,2,3), (0,1), (0,1)
The default mode returns:
+CNMI: 2, 1, 0, 0, 1
When i send a message i do not receive a delivery report.
I tried changing my CNMI to
2, 1, 2, 1, 0
but my sim card and d-link modem storage still have not stored any messages.
This process has worked on my (Huawei) modem that had this CNMI:
"AT+CNMI=2,1,2,2,0"
I tested these CNMI configs on my D-Link modem but it did not works
2, 1, 0, 0, 1
2, 1, 0, 1, 1
2, 1, 2, 0, 1
2, 1, 1, 1, 1
2, 1, 3, 0, 1
2, 1, 3, 1, 1
Old question but..
I am using AT+CSMS=1;+CNMI=2,1,0,1,1, have tried this on some Telit modems.
I get the SMS-STATUS-REPORT directly over the serial port, it isn't stored as such in the modem. There is no reference to a memory storage in the message, only the length of the PDU.
When I get the report it looks like this :
+CDS: 24
<pdu>
Also, when I receive a SMS-STATUS-REPORT I need to send ACKnowledge to the modem/mobile network using the AT+CNMA command.
you can try this
AT+CNMI=1,2,0,0,0

Can't understand the error message in the if condition in R

My program written in R sometimes (not always, but almost always when the simulation is run for a large number of times) shows this error message:
Error in if (sum.wt1y1 == 0 | sum.wt2y2 == 0) zn[k] <- 0 else zn[k] <- (sum.wt1y1 * :
missing value where TRUE/FALSE needed
Can anyone explain me what is the meaning of this error message? I cannot find where the error is. The final output is a vector. Now in that vector up to some values it shows "values" but the rest are 0, 0, 0,..., 0 when the error message appears. If the error message do not appear, then all the positions of the vector is filled up with values (no zeros).
The error arises due to NA values usually:
if (NA == 0) print('foo')
# Error in if (NA == 0) print("foo") :
# missing value where TRUE/FALSE needed
The solution is to remove missing values or include a check for them:
if (!is.na(x) & x == 0) ...
Try this:
which(is.na( sum.wt1y1 == 0 | sum.wt2y2 == 0))
To expand on what #justin said, the error message is essentially telling you that it was expecting a T/F but did not get it.
When you see such an error, the best thing to do is to explore the value that is inside
the parens in your if( .... ) statement.
In this specific case, looking at sum.wt1y1 == 0 | sum.wt2y2 == 0 would probably help you find the culprit.

Resources