问:
Celery tasks running multiple times in Django application
For weeks now we have been having issues with tasks running multiple times (always twice actually). I have tried to reproduce this locally and did a lot of testing on our staging and production server, but I can not seem to reproduce it and find the issue. Right now I simply have no clue where to look.

-We have recently upgraded from celery v4 to v5, but this was together with many other upgrades.

-The issues are only with long running periodic tasks (celery beat) that takeabout 15 min. to complete.

-We run celery in a managed kubernetes environment with separate deployments for beat and worker. Both deployments currently have a single pod.

One example of a task running twice:

@idempotent_notification_task(notification_tag='CREDITS_DIRECTDEBIT_PAYMENT')
def create_directdebit_payments_for_credits():
    plus_admin_ids = Order.objects.filter(
        subscription__type=Subscription.PLUS, credits_auto_top_up_amount__gt=0).values_list('administration_id',
                                                                                flat=True)
    admins = Administration.objects.filter(id__in=plus_admin_ids)
    for admin in admins:
        remaining_credits = admin.remaining_credits
        if remaining_credits < 0:
            po_exists = PurchaseOrder.objects.filter(administration=admin,
                                                     created__date=today(),
                                                     service=PurchaseOrder.SERVICE.CREDITS).exists()
            if po_exists:
                print(f"PurchaseOrder for client {admin.title} already exists!")
                return

            purchase_order = PurchaseOrder.objects.create(
                administration=admin, service=PurchaseOrder.SERVICE.CREDITS,
                credits_amount=admin.order.first().credits_auto_top_up_amount)
            payment = create_credits_mollie_payment_directdebit(purchase_order)
            Notification.create_credits_directdebit_payment(purchase_order)
```
<p>In an attempt to create a fix I created a wrapper function to make the task idempotent, but even this did not fix the issue. The wrapper function works as expected during local testing, but I still see the objects in the task being created twice.</p>
<pre class="lang-py prettyprint-override"><code>def idempotent_notification_task(notification_tag):
    """
    Decorator function that makes the celery task related to a notification template idempotent
    """
    def decorator(function):
        def wrapper(*args, **kwargs):
            nt = NotificationTemplate.objects.select_for_update().get(tag=notification_tag)
            with atomic():
                if nt.last_sent is not None and nt.last_sent.date() == today():
                    print(f"Notification {notification_tag} already sent today")
                    return
                else:
                    function()
                    nt.last_sent = now()
                    nt.save()
        return wrapper
    return decorator
</code>```

One weird thing that I can not wrap my head around is that sometimes I see multiple tasks being received in the celery logs. Sometimes I see one task received and sometimes I can not find the logs of the tasks at all, but they are still executed.

Body:
For weeks now we have been having issues with tasks running multiple times (always twice actually). I have tried to reproduce this locally and did a lot of testing on our staging and production server, but I can not seem to reproduce it and find the issue. Right now I simply have no clue where to look.

-We have recently upgraded from celery v4 to v5, but this was together with many other upgrades.

-The issues are only with long running periodic tasks (celery beat) that takeabout 15 min. to complete.

-We run celery in a managed kubernetes environment with separate deployments for beat and worker. Both deployments currently have a single pod.

One example of a task running twice:

@idempotent_notification_task(notification_tag='CREDITS_DIRECTDEBIT_PAYMENT')
def create_directdebit_payments_for_credits():
    plus_admin_ids = Order.objects.filter(
        subscription__type=Subscription.PLUS, credits_auto_top_up_amount__gt=0).values_list('administration_id',
                                                                                flat=True)
    admins = Administration.objects.filter(id__in=plus_admin_ids)
    for admin in admins:
        remaining_credits = admin.remaining_credits
        if remaining_credits < 0:
            po_exists = PurchaseOrder.objects.filter(administration=admin,
                                                     created__date=today(),
                                                     service=PurchaseOrder.SERVICE.CREDITS).exists()
            if po_exists:
                print(f"PurchaseOrder for client {admin.title} already exists!")
                return

            purchase_order = PurchaseOrder.objects.create(
                administration=admin, service=PurchaseOrder.SERVICE.CREDITS,
                credits_amount=admin.order.first().credits_auto_top_up_amount)
            payment = create_credits_mollie_payment_directdebit(purchase_order)
            Notification.create_credits_directdebit_payment(purchase_order)

In an attempt to create a fix I created a wrapper function to make the task idempotent, but even this did not fix the issue. The wrapper function works as expected during local testing, but I still see the objects in the task being created twice.

def idempotent_notification_task(notification_tag):
    """
    Decorator function that makes the celery task related to a notification template idempotent
    """
    def decorator(function):
        def wrapper(*args, **kwargs):
            nt = NotificationTemplate.objects.select_for_update().get(tag=notification_tag)
            with atomic():
                if nt.last_sent is not None and nt.last_sent.date() == today():
                    print(f"Notification {notification_tag} already sent today")
                    return
                else:
                    function()
                    nt.last_sent = now()
                    nt.save()
        return wrapper
    return decorator

One weird thing that I can not wrap my head around is that sometimes I see multiple tasks being received in the celery logs. Sometimes I see one task received and sometimes I can not find the logs of the tasks at all, but they are still executed.


来源: stackexchange

问:
Allow opening links in mobile browser mode
My H5 code does not work in Electron. It has the same problem as when I open a file in a computer browser. When I use the mobile mode of the browser, this problem no longer exists.I hope Electron has the function of packaging in H5 mode.

quasar + q-select + showPopup()

https://v1.quasar.dev/vue-components/select

ContentLicense: CC BY-SA 4.0


问:
how to configure Spring Boot HikariPool for use with AWS RDS Proxy?
I'm using RDS Proxy Endpoint(Writer/Reader, Reader).

1 writer-instance and 1 reader-instance are running. reader-instance CPU's nearly 90%.

so i've been trying to add 1 more reader instance.

I expected it distribute traffic immediately, automatically .

Hikari Settings -

```<code>spring.datasource.hikari.maximum-pool-size=100
spring.datasource.hikari.minimum-idle=100
spring.datasource.hikari.max-lifetime: 3600000 ( 1 hour )
</code>```

but It was not distribute traffic and i should wait end of hikari max-lifetime.

Should i change the max-lifetime to minimum? is this the best way?

ps) i prefer to use connection pooling because it is not serverless architecture, not micro services.
and if not using, because of not reuse connection, EKS pod's CPU will be 100%. so i would have to increase more and more eks pods count.

Body:
I'm using RDS Proxy Endpoint(Writer/Reader, Reader).

1 writer-instance and 1 reader-instance are running. reader-instance CPU's nearly 90%.

so i've been trying to add 1 more reader instance.

I expected it distribute traffic immediately, automatically .

Hikari Settings -

spring.datasource.hikari.maximum-pool-size=100
spring.datasource.hikari.minimum-idle=100
spring.datasource.hikari.max-lifetime: 3600000 ( 1 hour )

but It was not distribute traffic and i should wait end of hikari max-lifetime.

Should i change the max-lifetime to minimum? is this the best way?

ps) i prefer to use connection pooling because it is not serverless architecture, not micro services.
and if not using, because of not reuse connection, EKS pod's CPU will be 100%. so i would have to increase more and more eks pods count.


问:
How can I add a Hyperlink to reset password in the Email?
Can we include a link to Reset Password in the Email, in addition to the OTP in Azure B2C Custom Policies?
I am currently working on the Password Reset flow and it is working fine with the OTP. I now want to add a link in the email too, where the user can click and be redirected back to IDP where he/she can change the password.

I tried to find a solution for it, but couldn't.


问:
react-native app crashing android 13 but fine on android 11
Here is the issue on android studio .</p>
```<code>Error while executing: am start -n "package.name.of.my.app.callerid_test/package.name.of.my.app.callerid.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=ppackage.name.of.my.app.callerid_test/package.name.of.my.app.callerid.MainActivity }
Error type 3
Error: Activity class {package.name.of.my.app.callerid_test/package.name.of.my.app.callerid.MainActivity} does not exist.

Error while Launching activity
Failed to launch an application on all devices
</code>```

Body:
Here is the issue on android studio .

Error while executing: am start -n "package.name.of.my.app.callerid_test/package.name.of.my.app.callerid.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=ppackage.name.of.my.app.callerid_test/package.name.of.my.app.callerid.MainActivity }
Error type 3
Error: Activity class {package.name.of.my.app.callerid_test/package.name.of.my.app.callerid.MainActivity} does not exist.

Error while Launching activity
Failed to launch an application on all devices


问:
does mongodb node js driver has blocking code
I am using mongo db mongodb@4.7.0 driver. While investigation the performance issue of my application.To check if in my application is there any blocking code. I have used blocked-at npm module,so that module has given at two places in mongodb driver it have blocking code.

```<code>mongodb\\lib\\cmap\\message_stream.js:33:9

mongodb\\lib\\operations\\execute_operation.js:145:14
</code>```

message_stream.js there is one function called processIncomingData, which I can see is called recursively.

Please help me understand if there is any performance issue with mongodb driver.

Thanks

I have executed the performence analysis with increasing connection pool siz, still I am getting same response that two of above mentioned funcations are blocking the main thread.

Body:
I am using mongo db mongodb@4.7.0 driver. While investigation the performance issue of my application.To check if in my application is there any blocking code. I have used blocked-at npm module,so that module has given at two places in mongodb driver it have blocking code.

mongodb\\lib\\cmap\\message_stream.js:33:9

mongodb\\lib\\operations\\execute_operation.js:145:14

message_stream.js there is one function called processIncomingData, which I can see is called recursively.

Please help me understand if there is any performance issue with mongodb driver.

Thanks

I have executed the performence analysis with increasing connection pool siz, still I am getting same response that two of above mentioned funcations are blocking the main thread.


问:
WPF: How to handle null values in DataGrid?
I am a "fresh" WPF developer (I started 3 month ago), so this may be relative easy to solve for an expert (I hope so!)

I have create a view which summaries the processing results. For a better overview, all is packed into a DataGrid.

I am also using a custom Behavior to auto format the table content according to column data type base on How to set the StringFormat for specific columns in a WPF Datagrid whose values are populated via ItemsSource method

All works fine as long as all cells contains a non null value. When a cell is empty or filled with DBNull.Value, following exception is generated: property not found on object of type DataRowView

The DataTable is generated by code (C#), something like this:

```<code>ValueTable = new DataTable("DataTable");

// add timeline
DataColumn dtColumn = new DataColumn
                    {
                        DataType = typeof(double),
                        ColumnName = DefaultColumnName,
                        Caption = DefaultColumnName,
                        ReadOnly = true,
                        Unique = true
                    };
ValueTable.Columns.Add(dtColumn);
ValueTable.PrimaryKey = new DataColumn[] { ValueTable.Columns[DefaultColumnName] };
foreach(var col in MyData)
{
    dtColumn = new DataColumn
    {
        DataType = typeof(double),
        ColumnName = col.Name,
        Caption = col.Name,
        ReadOnly = true,
        Unique = false,
        AllowDBNull= true
    };
    ValueTable.Columns.Add(dtColumn);
}

...
// fill the columns
foreach(double currentTimein TimeLine)
{
    DataRow myDataRow = ValueTable.NewRow();
    myDataRow[DefaultColumnName] = currentTime;
    foreach(var col in MyData)
    {
        myDataRow[col.Name] = col.HasDataFor(currentTime) ? col.GetValue(currentTime) : DBNull.Value;
    }
    ValueTable.Rows.Add(myDataRow);
}
</code>```

And on WPF side:

```<code><DataGrid ItemsSource="{Binding ValueTable}" ClipboardCopyMode="IncludeHeader" IsReadOnly="True">
    <!-- Attach the behavior for autoformating the float values -->
    <i:Interaction.Behaviors>
        <l:AutoColumnFormatBehavior FloatFormat="0.#####"/>
    </i:Interaction.Behaviors>
</DataGrid>
</code>```

Note: removing the attached Behavior don't change anything.

Note2: when a row contains a null value, the hole row is showed as empty, but on copy/past all values are copied!

Any suggestion?

Regards

Body:
I am a "fresh" WPF developer (I started 3 month ago), so this may be relative easy to solve for an expert (I hope so!)

I have create a view which summaries the processing results. For a better overview, all is packed into a DataGrid.

I am also using a custom Behavior to auto format the table content according to column data type base on How to set the StringFormat for specific columns in a WPF Datagrid whose values are populated via ItemsSource method

All works fine as long as all cells contains a non null value. When a cell is empty or filled with DBNull.Value, following exception is generated: property not found on object of type DataRowView

The DataTable is generated by code (C#), something like this:

ValueTable = new DataTable("DataTable");

// add timeline
DataColumn dtColumn = new DataColumn
                    {
                        DataType = typeof(double),
                        ColumnName = DefaultColumnName,
                        Caption = DefaultColumnName,
                        ReadOnly = true,
                        Unique = true
                    };
ValueTable.Columns.Add(dtColumn);
ValueTable.PrimaryKey = new DataColumn[] { ValueTable.Columns[DefaultColumnName] };
foreach(var col in MyData)
{
    dtColumn = new DataColumn
    {
        DataType = typeof(double),
        ColumnName = col.Name,
        Caption = col.Name,
        ReadOnly = true,
        Unique = false,
        AllowDBNull= true
    };
    ValueTable.Columns.Add(dtColumn);
}

...
// fill the columns
foreach(double currentTimein TimeLine)
{
    DataRow myDataRow = ValueTable.NewRow();
    myDataRow[DefaultColumnName] = currentTime;
    foreach(var col in MyData)
    {
        myDataRow[col.Name] = col.HasDataFor(currentTime) ? col.GetValue(currentTime) : DBNull.Value;
    }
    ValueTable.Rows.Add(myDataRow);
}

And on WPF side:

<DataGrid ItemsSource="{Binding ValueTable}" ClipboardCopyMode="IncludeHeader" IsReadOnly="True">

        <l:AutoColumnFormatBehavior FloatFormat="0.#####"/>

</DataGrid>

Note: removing the attached Behavior don't change anything.

Note2: when a row contains a null value, the hole row is showed as empty, but on copy/past all values are copied!

Any suggestion?

Regards


问:
Numpy memmap and num_workers: Freezes and restart as executing multiple pytorch scripts
Mostly I work with huge file more than my workstation ram. So I uses numpy memmap file format with pytorch.
If I set num_workers more than 1, my workstation freezes and starts to reboot itself.

I tried to save those memmap files to each separate disks with the exactly same condition as num_workers = 1. But it still the same as freezing itself and starting to reboot.

Is there any solution or workaround for this situation?

Currently the maxium number of python script to execute simultaneously is two with num_workers=1.

from torch.utils.data import DataLoader, Dataset

def read_memmap(mem_file_name):
    with open(mem_file_name+'.conf', 'r') as file:
        memmap_configs = json.load(file)
        return np.memmap(mem_file_name, mode='r+', \
                        shape=tuple(memmap_configs['shape']), \
                        dtype=memmap_configs['dtype'])

x = read_mmap(file_path)
y = read_mmap(file_path)

dset = Dataset(x, y)

def my_dataloader(dset, batch_size):
    return DataLoader(
                    dataset     = dset,
                    batch_size  = batch_size,
                    num_workers = 1,
                    pin_memory  = True,
                    )
```


问:
Pinescript HTF condition not displaying on LTF correctly
I'm trying to create levels on lower timeframes based on higher timeframe conditional candles using their open or close, so in this case the H4 candle opens below the H4 9 EMA then close above colouring the candle and creating the condition etc.

Displays as expected on H4 but when go to LTF no idea what's going on. Found the line drawing script from looking around so unsure if issue lies there or with the security request - please help!

```<code>//@version=5
indicator(title="MBFX H4 Booster Levels", shorttitle="MBFX H4 Booster Levels", overlay=true)

//Input
showEMA1 = input(true, title="Show EMA1")
src1 = input(close, title="Source EMA1")
EMA_tf = input(defval='240', title="Timeframe EMA1")
length1 = input.int(9, minval=1, title="Length EMA1")
HTF_tf = input(defval='240', title="Timeframe")

//MTF EMA
EMA1 = ta.ema(src1,length1)
EMAMTF = request.security(syminfo.tickerid, EMA_tf, EMA1, barmerge.gaps_on)
plot(EMAMTF, "EMA1", color=#ffffff, display = showEMA1 ? display.all : display.none)

//Condition
rocup =  open < EMAMTF and  close > EMAMTF
rocdwn = open > EMAMTF and close < EMAMTF

//Build HTF Condition Bars
rocupD1 = request.security(syminfo.tickerid, HTF_tf, rocup, barmerge.gaps_on)
rocdnD1 = request.security(syminfo.tickerid, HTF_tf, rocdwn, barmerge.gaps_on)

c_barColor1 = rocup ? color.new(#4d42e8, 0) : rocdwn ? color.new(#ff9ff1, 11) : na
barcolor(c_barColor1)

// Draw lines from HTF condition candles open and close
int MAX_LINES_COUNT1 = 500
int linesToKeepInput1 = input.int(2, minval = 1, maxval = MAX_LINES_COUNT1,title="Max lines back")
int Extender1 = input.int(25, minval = 1, maxval = MAX_LINES_COUNT1, title="Extend lines")

//Draws line from close of HTF candle
if rocupD1 or rocdnD1
    color lineColor = rocupD1 ? color.new(#41ec50, 0) : color.new(#ffffff, 0)
    line.new(bar_index, close, bar_index+1, close, color = lineColor, width = 1)
// Once the new line is created, delete the oldest one if we have too many.
   if array.size(line.all) > linesToKeepInput1
     line.delete(array.get(line.all, 0))
     int(na)
else
    // Extend all visible lines.
    int lineNo = 0
    while lineNo < array.size(line.all)
        line.set_x2(array.get(line.all, lineNo), bar_index + Extender1)
        lineNo += 1
    int(na)

//Draws line from open of HTF candle
if rocupD1 or rocdnD1
    color lineColor = rocupD1 ? color.new(#ff1e00, 0) : color.new(#501547, 0)
    line.new(bar_index, open, bar_index+1, open, color = lineColor, width = 1)
    // Once the new line is created, delete the oldest one if we have too many.
    if array.size(line.all) > linesToKeepInput1
        line.delete(array.get(line.all, 0))
    int(na)
else
    // Extend all visible lines.
    int lineNo = 0
    while lineNo < array.size(line.all)
        line.set_x2(array.get(line.all, lineNo), bar_index + Extender1)
        lineNo += 1
    int(na)
</code>```

Correct display on H4

view on 30min as example

Should look like this

Have also recoded as below from https://www.tradingview.com/pine-script-docs/en/v5/concepts/Lines_and_boxes.html without lookback but still same issue.

```<code>    //@version=5
indicator(title="MBFX H4 Booster Levels", shorttitle="MBFX H4 Booster Levels", overlay=true)

//Input
showEMA1 = input(true, title="Show EMA1")
src1 = input(close, title="Source EMA1")
EMA_tf = input(defval='240', title="Timeframe EMA1")
length1 = input.int(9, minval=1, title="Length EMA1")

//MTF EMA
EMA1 = ta.ema(src1,length1)
EMAMTF = request.security(syminfo.tickerid, EMA_tf, EMA1, barmerge.gaps_on)
plot(EMAMTF, "EMA1", color=#ffffff, display = showEMA1 ? display.all : display.none)

//Condition
rocup =  ta.crossover(close, EMAMTF) and  open < EMAMTF
//rocdwn = open > EMAMTF and close < EMAMTF

string tfInput = input.timeframe("240", "Timeframe")
// Initialize variables on bar zero only, so they preserve their values across bars.
var hi = float(na)
var lo = float(na)
var line hiLine = na
var line loLine = na
var box hiLoBox = na
// Detect changes in timeframe.
bool newTF = ta.change(time(tfInput))

if newTF and rocup
    // New bar in higher timeframe; reset values and create new lines and box.
    hi := close
    lo := open
    hiLine := line.new(bar_index, hi, bar_index, hi, color = color.green, width = 2)
    loLine := line.new(bar_index, lo, bar_index, lo, color = color.red, width = 2)
// hiLoBox := box.new(bar_index - 1, hi, bar_index, lo, border_color = na, bgcolor = color.silver)
    int(na)
else
    // On other bars, extend the right coordinate of lines and box.
    line.set_x2(hiLine, bar_index)
    line.set_x2(loLine, bar_index)
// box.set_right(hiLoBox, bar_index)

c_barColor1 = rocup ? color.new(#4d42e8, 0) : na
barcolor(c_barColor1)
</code>```

Body:
I'm trying to create levels on lower timeframes based on higher timeframe conditional candles using their open or close, so in this case the H4 candle opens below the H4 9 EMA then close above colouring the candle and creating the condition etc.

Displays as expected on H4 but when go to LTF no idea what's going on. Found the line drawing script from looking around so unsure if issue lies there or with the security request - please help!

//@version=5
indicator(title="MBFX H4 Booster Levels", shorttitle="MBFX H4 Booster Levels", overlay=true)

//Input
showEMA1 = input(true, title="Show EMA1")
src1 = input(close, title="Source EMA1")
EMA_tf = input(defval='240', title="Timeframe EMA1")
length1 = input.int(9, minval=1, title="Length EMA1")
HTF_tf = input(defval='240', title="Timeframe")

//MTF EMA
EMA1 = ta.ema(src1,length1)
EMAMTF = request.security(syminfo.tickerid, EMA_tf, EMA1, barmerge.gaps_on)
plot(EMAMTF, "EMA1", color=#ffffff, display = showEMA1 ? display.all : display.none)

//Condition
rocup =  open < EMAMTF and  close > EMAMTF
rocdwn = open > EMAMTF and close < EMAMTF

//Build HTF Condition Bars
rocupD1 = request.security(syminfo.tickerid, HTF_tf, rocup, barmerge.gaps_on)
rocdnD1 = request.security(syminfo.tickerid, HTF_tf, rocdwn, barmerge.gaps_on)

c_barColor1 = rocup ? color.new(#4d42e8, 0) : rocdwn ? color.new(#ff9ff1, 11) : na
barcolor(c_barColor1)

// Draw lines from HTF condition candles open and close
int MAX_LINES_COUNT1 = 500
int linesToKeepInput1 = input.int(2, minval = 1, maxval = MAX_LINES_COUNT1,title="Max lines back")
int Extender1 = input.int(25, minval = 1, maxval = MAX_LINES_COUNT1, title="Extend lines")

//Draws line from close of HTF candle
if rocupD1 or rocdnD1
    color lineColor = rocupD1 ? color.new(#41ec50, 0) : color.new(#ffffff, 0)
    line.new(bar_index, close, bar_index+1, close, color = lineColor, width = 1)
// Once the new line is created, delete the oldest one if we have too many.
   if array.size(line.all) > linesToKeepInput1
     line.delete(array.get(line.all, 0))
     int(na)
else
    // Extend all visible lines.
    int lineNo = 0
    while lineNo < array.size(line.all)
        line.set_x2(array.get(line.all, lineNo), bar_index + Extender1)
        lineNo += 1
    int(na)

//Draws line from open of HTF candle
if rocupD1 or rocdnD1
    color lineColor = rocupD1 ? color.new(#ff1e00, 0) : color.new(#501547, 0)
    line.new(bar_index, open, bar_index+1, open, color = lineColor, width = 1)
    // Once the new line is created, delete the oldest one if we have too many.
    if array.size(line.all) > linesToKeepInput1
        line.delete(array.get(line.all, 0))
    int(na)
else
    // Extend all visible lines.
    int lineNo = 0
    while lineNo < array.size(line.all)
        line.set_x2(array.get(line.all, lineNo), bar_index + Extender1)
        lineNo += 1
    int(na)

Correct display on H4

view on 30min as example

Should look like this

Have also recoded as below from https://www.tradingview.com/pine-script-docs/en/v5/concepts/Lines_and_boxes.html without lookback but still same issue.

    //@version=5
indicator(title="MBFX H4 Booster Levels", shorttitle="MBFX H4 Booster Levels", overlay=true)

//Input
showEMA1 = input(true, title="Show EMA1")
src1 = input(close, title="Source EMA1")
EMA_tf = input(defval='240', title="Timeframe EMA1")
length1 = input.int(9, minval=1, title="Length EMA1")

//MTF EMA
EMA1 = ta.ema(src1,length1)
EMAMTF = request.security(syminfo.tickerid, EMA_tf, EMA1, barmerge.gaps_on)
plot(EMAMTF, "EMA1", color=#ffffff, display = showEMA1 ? display.all : display.none)

//Condition
rocup =  ta.crossover(close, EMAMTF) and  open < EMAMTF
//rocdwn = open > EMAMTF and close < EMAMTF

string tfInput = input.timeframe("240", "Timeframe")
// Initialize variables on bar zero only, so they preserve their values across bars.
var hi = float(na)
var lo = float(na)
var line hiLine = na
var line loLine = na
var box hiLoBox = na
// Detect changes in timeframe.
bool newTF = ta.change(time(tfInput))

if newTF and rocup
    // New bar in higher timeframe; reset values and create new lines and box.
    hi := close
    lo := open
    hiLine := line.new(bar_index, hi, bar_index, hi, color = color.green, width = 2)
    loLine := line.new(bar_index, lo, bar_index, lo, color = color.red, width = 2)
// hiLoBox := box.new(bar_index - 1, hi, bar_index, lo, border_color = na, bgcolor = color.silver)
    int(na)
else
    // On other bars, extend the right coordinate of lines and box.
    line.set_x2(hiLine, bar_index)
    line.set_x2(loLine, bar_index)
// box.set_right(hiLoBox, bar_index)

c_barColor1 = rocup ? color.new(#4d42e8, 0) : na
barcolor(c_barColor1)


问:
Chrome Custom Tabs not working as expected (Kotlin) (Android)
I am relatively new to using Chrome Custom Tabs, from what I have experienced certain methods are not working. For example methods that are working include

Setting the color of the toolbar

```<code>        val builder = CustomTabsIntent.Builder()

        // modify toolbar color
        builder.setToolbarColor(ContextCompat.getColor(this@MainActivity, R.color.colorPrimary))
</code>```

Adding a new item on the menu

```<code>            val requestCode = 100
        val intent = anotherCustomTab.intent
        intent.setData(Uri.parse("https://facebook.com/"))

        val pendingIntent = PendingIntent.getActivity(this,
                requestCode,
                intent,
                PendingIntent.FLAG_UPDATE_CURRENT)

        // add menu item to oveflow
        builder.addMenuItem("Sample item", pendingIntent)
</code>```

However methods that don't seem to work include

Setting icon for the back button and creating a new Action Button

```<code>     val builder = CustomTabsIntent.Builder()
     val bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)
     builder.setActionButton(bitmap, "Android", pendingIntent, true)

     builder.setCloseButtonIcon(bitmap)
</code>```

I don't know if it is just me but some of the docs seem to be misleading, for example

For example according to the official chrome custom tab guide, in order to change the color of the address/toolbar we need to do this

```<code> val builder = CustomTabsIntent.Builder()
val colorInt: Int = Color.parseColor("#FF0000") //red

val defaultColors: CustomTabColorSchemeParams = Builder()
            .setToolbarColor(colorInt)
            .build()
        builder.setDefaultColorSchemeParams(defaultColors)
</code>```

However when I am trying to implement this in my IDE an error would occur Unresolved reference: setDefaultColorSchemeParams, which doesn't make sense as this method is present in the docs as well, the only thing I could think of is perhaps it was removed?

Another example I can think of is implementing the CustomTabSessions class, according to the docs, creating an instance of the CustomTabSessions requires no parameters, however when trying it out in my IDE it requires 3 parameters which includes callback, componentName and service

Note I am quite unfamiliar with java perhaps I am interpreting the Docs wrongly.

Body:
I am relatively new to using Chrome Custom Tabs, from what I have experienced certain methods are not working. For example methods that are working include

Setting the color of the toolbar

        val builder = CustomTabsIntent.Builder()

        // modify toolbar color
        builder.setToolbarColor(ContextCompat.getColor(this@MainActivity, R.color.colorPrimary))

Adding a new item on the menu

            val requestCode = 100
        val intent = anotherCustomTab.intent
        intent.setData(Uri.parse("https://facebook.com/"))

        val pendingIntent = PendingIntent.getActivity(this,
                requestCode,
                intent,
                PendingIntent.FLAG_UPDATE_CURRENT)

        // add menu item to oveflow
        builder.addMenuItem("Sample item", pendingIntent)

However methods that don't seem to work include

Setting icon for the back button and creating a new Action Button

     val builder = CustomTabsIntent.Builder()
     val bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)
     builder.setActionButton(bitmap, "Android", pendingIntent, true)

     builder.setCloseButtonIcon(bitmap)

I don't know if it is just me but some of the docs seem to be misleading, for example

For example according to the official chrome custom tab guide, in order to change the color of the address/toolbar we need to do this

 val builder = CustomTabsIntent.Builder()
val colorInt: Int = Color.parseColor("#FF0000") //red

val defaultColors: CustomTabColorSchemeParams = Builder()
            .setToolbarColor(colorInt)
            .build()
        builder.setDefaultColorSchemeParams(defaultColors)

However when I am trying to implement this in my IDE an error would occur Unresolved reference: setDefaultColorSchemeParams, which doesn't make sense as this method is present in the docs as well, the only thing I could think of is perhaps it was removed?

Another example I can think of is implementing the CustomTabSessions class, according to the docs, creating an instance of the CustomTabSessions requires no parameters, however when trying it out in my IDE it requires 3 parameters which includes callback, componentName and service

Note I am quite unfamiliar with java perhaps I am interpreting the Docs wrongly.


问:
Set response headers per file for statically hosted files
Is there a way to have nginx serve up static content with custom headers - but being able to set these headers per file (and not in the nginx configuration)

Eg. if I request http://127.0.0.1/attachment-12345 I would like nginx to use try_files to find the file 'attachment-12345' and serve it... but to also look at 'attachment-12345.headers', take Content-Type: application/msword\nContent-Disposition: attachment; name="abc.doc"\nCache-Control: immutable from that file and serve those headers. So nothing based on extension, and each file can have its own headers.

(This would allow me to somewhat simulate a S3/Cloudfront based cache using local disk... as S3 allows me to set a subset of HTTP headers for every file)


问:
Can not open react native app in android 12
It throws us the error,
"MediaSessionCompat:Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent"

We have tried adding line "implementation 'androidx.work:work-runtime-ktx:2.7.1'".

But it doesn't solve our issue.
How can we resolve this?


问:
How to style container widgets like a pagelist or splitview without pitfals (see details) - CSS
I'm making a JS widget library and I need to style a container widget like a pagelist or a splitview and I can't get around certain pitfals.

I can't use the " " combinator for styling inner elements of the widget because that accidentaly touches the contained widgets too.

To fix that, I'm using the ">" combinator but that couples the styling to the DOM structure for no good reason and creates a lot of repetition.

To avoid that I'd have to set state classes (like .invalid) to all inner elements of the widget, not just to the widget itself (outermost element) and that's also repetitive and error-prone. To avoid that, I could set the .invalid class to the innermost element and then I can use :has(.invalid) on any outer element. That means also setting tabindex=0 to the innermost element so that I can use :has(:focus-visible) on any outer element. But those are hacks and sometimes there is no single innermost element.

Those hacks create specificity bugs.

If anyone has written a widget library with container widgets, are there any good ideas to work around these problems?

Would-be solutions that don't exist in CSS:

a CSS combinator similar to " " that would not match further down a subtree after a first match in that subtree.

a pseudo-selector that matches a selector in an element's parent chain like eg. :ancestor-has(.invalid).


问:
Resource search does not exist - LinkedIn API
I have some issue with linkedin api. The search endpoint (to search posts by keyword) is not accessible to me. I got permissions for Marketing Developer Platform. My permission scope is:

r_1st_connections_size,r_ads,r_ads_reporting,r_basicprofile,r_organization_admin,r_organization_social,rw_ads,rw_organization_admin,w_member_social,w_organization_social

I assumed search endpoint would be included into this scope. Do I miss anything?

I am trying to use search api in the following way: https://api.linkedin.com/v2/search?q=LinkedIn API&type=post and using my access token. But I get error:

```<code>{
   "serviceErrorCode": 0,
   "message": "Resource search does not exist",
   "status": 404
}
</code>```

Body:
I have some issue with linkedin api. The search endpoint (to search posts by keyword) is not accessible to me. I got permissions for Marketing Developer Platform. My permission scope is:

r_1st_connections_size,r_ads,r_ads_reporting,r_basicprofile,r_organization_admin,r_organization_social,rw_ads,rw_organization_admin,w_member_social,w_organization_social

I assumed search endpoint would be included into this scope. Do I miss anything?

I am trying to use search api in the following way: https://api.linkedin.com/v2/search?q=LinkedIn API&type=post and using my access token. But I get error:

{
   "serviceErrorCode": 0,
   "message": "Resource search does not exist",
   "status": 404
}


问:
React prevent useContext from rerendering when only use the dispatch callback
I am building a component tree, where the controller of a state could be deeply nested in the tree, or nested in the siblings of the consumer of the state. Therefore I use Context.Provider to wrap the dispatch function and the state at the top level, then call useContext inside controller function to access the dispatch function.

Now the problem is, when I call dispatch function in controller, it will cause a change of the state of Context.Provider, then cause the controller component to rerender. Since the controller only uses the dispatch function, I think the rerender should be avoided.

An example:

const Context = React.createContext();

const AppContext = ({ children }) => {
  const [state, setState] = useState(true);
  return (
    <Context.Provider value={{ state, setState }}>
      {children}
    </Context.Provider>
  );
};

const ControllerButton = () => {
  const { setState } = useContext(Context); // only setState is called
  const onClick = () => {
    setState(oldState => !oldState);
  }
  // assume there are some other expensive computations so I would like to prevent it from rerendering
  return <button onClick={onClick}>Toggle</button>;
}

const App() => {
  return (
    <AppContext>
      <ControllerButton/>
      {/* ...consumers of state */}
    </AppContext>
  );
}
```
<p>Here I have several questions:</p>
<ol>
<li>For my needs (caller of dispatch function and consumer of state lives remotely in a complex react component tree), should I use <code>useContext</code> to implement it? Are there better options?</li>
<li>If I have to use <code>useContext</code>, one way to do so is to split it into 2 contexts. For example:</li>
</ol>
<pre class="lang-js prettyprint-override"><code>const StateContext = React.createContext();
const SetStateContext = React.createContext();

const AppContext = ({ children }) => {
  const [state, setState] = useState(true);
  return (
    <Context.Provider value={{ state }}>
      <SetStateContext.Provider value={{ setState }}>
        {children}
      </SetStateContext.Provider>
    </Context.Provider>
  );
};
</code>```

However, I found most implementations do not do so. Is it a good practice?

Alternatively, I can also make the rerender cost small enough, such as use React.memo:

const ControllerButtonInner({setState}) {
  const onClick = () => {
    setState(oldState => !oldState);
  }
  return <button onClick={onClick}>Toggle</button>;
}

}
const ControllerButton = () => {
  const { setState } = useContext(Context);

  return React.memo(<ControllerButtonInner setState={setState}/>);
}
```

Is it a good practice?

Or, is there any other approach to prevent it from rerender?

Body:
I am building a component tree, where the controller of a state could be deeply nested in the tree, or nested in the siblings of the consumer of the state. Therefore I use Context.Provider to wrap the dispatch function and the state at the top level, then call useContext inside controller function to access the dispatch function.

Now the problem is, when I call dispatch function in controller, it will cause a change of the state of Context.Provider, then cause the controller component to rerender. Since the controller only uses the dispatch function, I think the rerender should be avoided.

An example:

const Context = React.createContext();

const AppContext = ({ children }) => {
  const [state, setState] = useState(true);
  return (
    <Context.Provider value={{ state, setState }}>
      {children}
    </Context.Provider>
  );
};

const ControllerButton = () => {
  const { setState } = useContext(Context); // only setState is called
  const onClick = () => {
    setState(oldState => !oldState);
  }
  // assume there are some other expensive computations so I would like to prevent it from rerendering
  return <button onClick={onClick}>Toggle</button>;
}

const App() => {
  return (
    <AppContext>
      <ControllerButton/>
      {/* ...consumers of state */}
    </AppContext>
  );
}

Here I have several questions:

For my needs (caller of dispatch function and consumer of state lives remotely in a complex react component tree), should I use useContext to implement it? Are there better options?

If I have to use useContext, one way to do so is to split it into 2 contexts. For example:

const StateContext = React.createContext();
const SetStateContext = React.createContext();

const AppContext = ({ children }) => {
  const [state, setState] = useState(true);
  return (
    <Context.Provider value={{ state }}>
      <SetStateContext.Provider value={{ setState }}>
        {children}
      </SetStateContext.Provider>
    </Context.Provider>
  );
};

However, I found most implementations do not do so. Is it a good practice?

Alternatively, I can also make the rerender cost small enough, such as use React.memo:

const ControllerButtonInner({setState}) {
  const onClick = () => {
    setState(oldState => !oldState);
  }
  return <button onClick={onClick}>Toggle</button>;
}

}
const ControllerButton = () => {
  const { setState } = useContext(Context);

  return React.memo(<ControllerButtonInner setState={setState}/>);
}

Is it a good practice?

Or, is there any other approach to prevent it from rerender?


问:
Use a Web Worker to run TensorFlowJS hand pose detection

The goal:

I've got a functioning system that can detect hands with TensorFlowJS's [Hand Pose Detection][1]. However, each detection is slow, so I want to pull the model creation and inference into a Web Worker so that I can keep the UI responsive. However, I can't manage to figure out how to import everything I need.

(The system also uses another model coco-ssd for object detection/identification, plus a global variable in index.js to hold the detected hands data, and a global function to update this data, which might be unusual, but that's separate to this issue, I think.)

Functional, no Web Worker code:

index.js

```<code>import {CreateHandDetector, CreateObjectDetector, DetectObjects} from './models';

let globalHands = [];

async function Init() {
    await CreateHandDetector();
}

while(true) {
     await DetectObjects();
     /* At this point, I've got the hands data successfully */
}
</code>```

models.js

```<code>import * as handPoseDetection from '@tensorflow-models/hand-pose-detection';
require('@tensorflow/tfjs-backend-cpu');
require('@tensorflow/tfjs-backend-webgl');
const cocoSsd = require('@tensorflow-models/coco-ssd');

export async function CreateHandDetector() {
    const model = handPoseDetection.SupportedModels.MediaPipeHands;
    const detectorConfig = {
        runtime: 'mediapipe',
        solutionPath: 'https://cdn.jsdelivr.net/npm/@mediapipe/hands',
        modelType: 'lite'
    };
    detectors.handDetector = await handPoseDetection.createDetector(model, detectorConfig);
    console.log("Hand detector made");
}

export async function DetectObjects() {
     /* Some logic to cancel if hand detection turned off by user */
     await DetectHands();
}

async function DetectHands() {
    const video = document.querySelector("#liveVideo");
    const hands = await detectors.handDetector.estimateHands(video, {flipHorizontal: false});
     /* Some logic to modify the hands data and send it back */
}
</code>```

My attempt to migrate to a Web Worker

*index.js*
```<code>    const modelWorker = new Worker(new URL('./modelsWorker.js', import.meta.url), {type: "module"});
    modelWorker.onmessage = (e) => {
        const modelData = e.data;
        if(modelData.action === "ping")   { console.log(`Ping reply: ${modelData.message}`); }
        if(modelData.action === "init")   { console.log(`Ran init, reply: ${modelData.message}`); }
    }

    modelWorker.postMessage({action: "ping"}); // output: "Ping reply: pong"
    modelWorker.postMessage({action: "init"});
</code>```

modelsWorker.js

```<code>//require('@tensorflow-models/hand-pose-detection');
//import * as handPoseDetection from '@tensorflow-models/hand-pose-detection';
//import * as handPoseDetection from './tensorflowImports/hand-pose-detection';
importScripts('https://cdn.jsdelivr.net/npm/@tensorflow-models/hand-pose-detection');
//importScripts('./tensorflowImports/hand-pose-detection.js');
//require('./tensorflowImports/hand-pose-detection');
//const handPoseDetection = require('./tensorflowImports/hand-pose-detection');
//require('./tensorflowImports/hands');
//importScripts('https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-cpu');  // TypeError: a.kernel_impls is undefinedtfjs-backend-cpu:17:3180
//importScripts('https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-webgl');
require('./tensorflowImports/tfjs-backend-cpu');
require('./tensorflowImports/tfjs-backend-webgl');
const cocoSsd = require('./tensorflowImports/coco-ssd');

const detectors = {handDetector: null, objectDetector: null, pauseAll: false}

onmessage = async (e) => {
    const modelInputData = e.data;
    const returnData = {action: modelInputData.action};

    if(modelInputData.action === "ping") {
        console.log("pong");
        returnData.message = "pong";
        postMessage(returnData);
        return;
    }

    if(modelInputData.action === "init") {
        returnData.success = await CreateDetectors();
        postMessage(returnData);
    }
}

async function CreateDetectors() {
    await CreateHandDetector();
    /* Some logic that runs when the detector is created successfully */
    return true;
}

export async function CreateHandDetector() {
    const model = handPoseDetection.SupportedModels.MediaPipeHands;
    const detectorConfig = {
        runtime: 'mediapipe',
        solutionPath: 'https://cdn.jsdelivr.net/npm/@mediapipe/hands',
        modelType: 'lite'
    };

    // Dies here. Error:
    // TypeError: t.Hands is not a constructor    hand-pose-detection:17:2509
    detectors.handDetector = await handPoseDetection.createDetector(model, detectorConfig);

    console.log("Hand detector made"); // Never printed
}

</code>```

What I need

As you can see, I tried many different ways to import the hand detection model. All of them ended in tears. I assume I'm importing incorrectly, but who knows.

This answer just uses importScripts, but I can't replicate it.

This answer uses import {} from which I'd love to use, but doesn't work either.

Body:
The goal:

I've got a functioning system that can detect hands with TensorFlowJS's [Hand Pose Detection][1]. However, each detection is slow, so I want to pull the model creation and inference into a Web Worker so that I can keep the UI responsive. However, I can't manage to figure out how to import everything I need.

(The system also uses another model coco-ssd for object detection/identification, plus a global variable in index.js to hold the detected hands data, and a global function to update this data, which might be unusual, but that's separate to this issue, I think.)

Functional, no Web Worker code:

index.js

import {CreateHandDetector, CreateObjectDetector, DetectObjects} from './models';

let globalHands = [];

async function Init() {
    await CreateHandDetector();
}

while(true) {
     await DetectObjects();
     /* At this point, I've got the hands data successfully */
}

models.js

import * as handPoseDetection from '@tensorflow-models/hand-pose-detection';
require('@tensorflow/tfjs-backend-cpu');
require('@tensorflow/tfjs-backend-webgl');
const cocoSsd = require('@tensorflow-models/coco-ssd');

export async function CreateHandDetector() {
    const model = handPoseDetection.SupportedModels.MediaPipeHands;
    const detectorConfig = {
        runtime: 'mediapipe',
        solutionPath: 'https://cdn.jsdelivr.net/npm/@mediapipe/hands',
        modelType: 'lite'
    };
    detectors.handDetector = await handPoseDetection.createDetector(model, detectorConfig);
    console.log("Hand detector made");
}

export async function DetectObjects() {
     /* Some logic to cancel if hand detection turned off by user */
     await DetectHands();
}

async function DetectHands() {
    const video = document.querySelector("#liveVideo");
    const hands = await detectors.handDetector.estimateHands(video, {flipHorizontal: false});
     /* Some logic to modify the hands data and send it back */
}

My attempt to migrate to a Web Worker

*index.js*

    const modelWorker = new Worker(new URL('./modelsWorker.js', import.meta.url), {type: "module"});
    modelWorker.onmessage = (e) => {
        const modelData = e.data;
        if(modelData.action === "ping")   { console.log(`Ping reply: ${modelData.message}`); }
        if(modelData.action === "init")   { console.log(`Ran init, reply: ${modelData.message}`); }
    }

    modelWorker.postMessage({action: "ping"}); // output: "Ping reply: pong"
    modelWorker.postMessage({action: "init"});

modelsWorker.js

//require('@tensorflow-models/hand-pose-detection');
//import * as handPoseDetection from '@tensorflow-models/hand-pose-detection';
//import * as handPoseDetection from './tensorflowImports/hand-pose-detection';
importScripts('https://cdn.jsdelivr.net/npm/@tensorflow-models/hand-pose-detection');
//importScripts('./tensorflowImports/hand-pose-detection.js');
//require('./tensorflowImports/hand-pose-detection');
//const handPoseDetection = require('./tensorflowImports/hand-pose-detection');
//require('./tensorflowImports/hands');
//importScripts('https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-cpu');  // TypeError: a.kernel_impls is undefinedtfjs-backend-cpu:17:3180
//importScripts('https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-webgl');
require('./tensorflowImports/tfjs-backend-cpu');
require('./tensorflowImports/tfjs-backend-webgl');
const cocoSsd = require('./tensorflowImports/coco-ssd');

const detectors = {handDetector: null, objectDetector: null, pauseAll: false}

onmessage = async (e) => {
    const modelInputData = e.data;
    const returnData = {action: modelInputData.action};

    if(modelInputData.action === "ping") {
        console.log("pong");
        returnData.message = "pong";
        postMessage(returnData);
        return;
    }

    if(modelInputData.action === "init") {
        returnData.success = await CreateDetectors();
        postMessage(returnData);
    }
}

async function CreateDetectors() {
    await CreateHandDetector();
    /* Some logic that runs when the detector is created successfully */
    return true;
}

export async function CreateHandDetector() {
    const model = handPoseDetection.SupportedModels.MediaPipeHands;
    const detectorConfig = {
        runtime: 'mediapipe',
        solutionPath: 'https://cdn.jsdelivr.net/npm/@mediapipe/hands',
        modelType: 'lite'
    };

    // Dies here. Error:
    // TypeError: t.Hands is not a constructor    hand-pose-detection:17:2509
    detectors.handDetector = await handPoseDetection.createDetector(model, detectorConfig);

    console.log("Hand detector made"); // Never printed
}

What I need

As you can see, I tried many different ways to import the hand detection model. All of them ended in tears. I assume I'm importing incorrectly, but who knows.

This answer just uses importScripts, but I can't replicate it.

This answer uses import {} from which I'd love to use, but doesn't work either.


问:
heap exception in another thread cannot generate dump file C++
Currently, I have a problem with dump file. In general, I use the win32 api MiniDumpWriteDump to generate dump file when my App end with the crash. In most case, it's very useful. However, I found that the dump file cannot be generated when Heap Exception happened in another thread. the mini reproduce in follow section:
main.cpp
//main.cpp file

```<code>LONG WINAPI createMinidump(_EXCEPTION_POINTERS *apExceptionInfo)
{
    HMODULE mhLib = ::LoadLibraryA("dbghelp.dll");
    MINIDUMPWRITEDUMP pDump = (MINIDUMPWRITEDUMP)::GetProcAddress(mhLib, "MiniDumpWriteDump");

    HANDLE  hFile = ::CreateFileA("core.dmp", GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS,
        FILE_ATTRIBUTE_NORMAL, NULL);

    _MINIDUMP_EXCEPTION_INFORMATION ExInfo;
    ExInfo.ThreadId = ::GetCurrentThreadId();
    ExInfo.ExceptionPointers = apExceptionInfo;
    ExInfo.ClientPointers = FALSE;

    pDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpWithFullMemory , &ExInfo, NULL, NULL);
    ::CloseHandle(hFile);

    return EXCEPTION_CONTINUE_SEARCH;
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    SetUnhandledExceptionFilter(ExceptionHandler);

    MainWindow w;
    w.show();

    return a.exec();
}
</code>```

mainwindow.h

```<code>#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QLoggingCategory>
#include "testth.h"
#include <QThread>

Q_DECLARE_LOGGING_CATEGORY(MainWindowModule)

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
private:
signals:
    void testsignal();

private slots:

    void on_pushButton_clicked(bool checked);

private:
    Ui::MainWindow *ui;

    TestTh* m_t{Q_NULLPTR};
    QObject* m_To{Q_NULLPTR};

    QThread m_TestTH{};
};
#endif // MAINWINDOW_H
</code>```

//mainwindow.cpp

```<code>#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <qnetworkconfigmanager.h>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <qevent.h>
#include <QFile>
#include <QFileInfo>

Q_LOGGING_CATEGORY(MainWindowModule,"Main.Window.Module",QtMsgType::QtWarningMsg)

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow),m_t{new TestTh()}
{
    ui->setupUi(this);

    this->m_t->moveToThread(&m_TestTH);

    this->m_TestTH.start();

    connect(this,&MainWindow::testsignal,this->m_t,&TestTh::testSlot);
}

MainWindow::~MainWindow()
{
    this->m_TestTH.quit();

    this->m_TestTH.wait();

    delete ui;
}

void MainWindow::on_pushButton_clicked(bool checked)
{
//    this->m_To->thread();

    emit this->testsignal();
}
</code>```

testth.cpp

```<code>#ifndef TESTTH_H
#define TESTTH_H

#include <QObject>
#include <QThread>

class TestTh : public QObject
{
    Q_OBJECT
public:
    TestTh();
    virtual ~TestTh()=default;
public slots:
    void testSlot();
private:

    QObject* m_A{};
    QObject* m_B{};

};

#endif // TESTTH_H
</code>```

test.cpp

```<code>#include "testth.h"
#include <QDebug>

TestTh::TestTh()
{

}

void TestTh::testSlot()
{
    auto d=new int[1000];
    delete []d;
    delete []d;
    qDebug()<<"test slot func";
}
</code>```

In above code, the app will be crashed when I push the button. Beacuse, I double delete the array in the member testSlot. However, there is no any dump file generated. after some probe, I have been told that api MiniDumpWriteDump should be called in target process.Hence, I have some midification to my project, As showing in following section:

```<code>#include "mainwindow.h"

//#include <Windows.h>
#include <QApplication>
#include <QFile>
#include <QDeadlineTimer>
#include <QDebug>
#include <QSaveFile>
#include <QStringBuilder>
#include <QTextStream>
#include <mutex>
#include <QDateTime>

#include <QFileInfo>
//#include <minidumpapiset.h>
#include <io.h>
#include <QScopedPointer>
#include <QProcess>

auto WINAPI ExceptionHandler(LPEXCEPTION_POINTERS pException)->long
{
    QScopedPointer<QProcess> anotherExe{new QProcess()};
    anotherExe->setWorkingDirectory(qApp->applicationDirPath());
    anotherExe->setProgram(qApp->applicationDirPath() % QStringLiteral("/CrashDumpGuardor.exe"));

    auto pidPro=QString::number(GetCurrentProcessId());

    auto threadId=GetCurrentThreadId();

    char exceptionContent[32768];

    sprintf_s(exceptionContent,sizeof(exceptionContent)/sizeof (exceptionContent[0]),"%p",pException);

    anotherExe->setArguments(QStringList{pidPro,QString::number(threadId),QString::fromLatin1(exceptionContent),qApp->applicationDirPath()});
    anotherExe->start();
    anotherExe->waitForFinished();

    return TRUE;
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    SetUnhandledExceptionFilter(ExceptionHandler);

    MainWindow w;
    w.show();

    return a.exec();
}
</code>```

for more details, I move the minidumpwritedump to another project named CrashDumpGuardor an that generate an exe named CrashDumpGuardor.exe that was placed on my crash app dir.I will create the sub process to call CrashDumpGuardor.exe with some argument. unfortunately, this method have any affect. there is no dump file generation.

after these attempations, I have tried with google breakpad in the

```<code>following section:
#include <QFileInfo>
#include <io.h>
#include <QScopedPointer>
#include <QProcess>
#include "breakpad/client/windows/handler/exception_handler.h"
using namespace google_breakpad;

static bool callback(const wchar_t *dump_path, const wchar_t *id,
    void *, EXCEPTION_POINTERS *,
    MDRawAssertionInfo *,
    bool succeeded) {
    if (succeeded)
        qWarning("Dump file created in %s, dump guid is %ws\n", dump_path, id);
    else
        qWarning("Dump failed\n");
    return succeeded;
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    ExceptionHandler eh(qApp->applicationDirPath().toStdWString().c_str(), NULL, callback, NULL,
                        ExceptionHandler::HANDLER_ALL);

    MainWindow w;
    w.show();

    return a.exec();
}
</code>```

However, there is also no dump file generation, I'm really have no ideal to handle this problem, can someone give an assistance to me, Thanks!!!!

Body:
Currently, I have a problem with dump file. In general, I use the win32 api MiniDumpWriteDump to generate dump file when my App end with the crash. In most case, it's very useful. However, I found that the dump file cannot be generated when Heap Exception happened in another thread. the mini reproduce in follow section:
main.cpp
//main.cpp file

LONG WINAPI createMinidump(_EXCEPTION_POINTERS *apExceptionInfo)
{
    HMODULE mhLib = ::LoadLibraryA("dbghelp.dll");
    MINIDUMPWRITEDUMP pDump = (MINIDUMPWRITEDUMP)::GetProcAddress(mhLib, "MiniDumpWriteDump");

    HANDLE  hFile = ::CreateFileA("core.dmp", GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS,
        FILE_ATTRIBUTE_NORMAL, NULL);

    _MINIDUMP_EXCEPTION_INFORMATION ExInfo;
    ExInfo.ThreadId = ::GetCurrentThreadId();
    ExInfo.ExceptionPointers = apExceptionInfo;
    ExInfo.ClientPointers = FALSE;

    pDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpWithFullMemory , &ExInfo, NULL, NULL);
    ::CloseHandle(hFile);

    return EXCEPTION_CONTINUE_SEARCH;
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    SetUnhandledExceptionFilter(ExceptionHandler);

    MainWindow w;
    w.show();

    return a.exec();
}

mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QLoggingCategory>
#include "testth.h"
#include <QThread>

Q_DECLARE_LOGGING_CATEGORY(MainWindowModule)

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
private:
signals:
    void testsignal();

private slots:

    void on_pushButton_clicked(bool checked);

private:
    Ui::MainWindow *ui;

    TestTh* m_t{Q_NULLPTR};
    QObject* m_To{Q_NULLPTR};

    QThread m_TestTH{};
};
#endif // MAINWINDOW_H

//mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <qnetworkconfigmanager.h>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <qevent.h>
#include <QFile>
#include <QFileInfo>

Q_LOGGING_CATEGORY(MainWindowModule,"Main.Window.Module",QtMsgType::QtWarningMsg)

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow),m_t{new TestTh()}
{
    ui->setupUi(this);

    this->m_t->moveToThread(&m_TestTH);

    this->m_TestTH.start();

    connect(this,&MainWindow::testsignal,this->m_t,&TestTh::testSlot);
}

MainWindow::~MainWindow()
{
    this->m_TestTH.quit();

    this->m_TestTH.wait();

    delete ui;
}

void MainWindow::on_pushButton_clicked(bool checked)
{
//    this->m_To->thread();

    emit this->testsignal();
}

testth.cpp

#ifndef TESTTH_H
#define TESTTH_H

#include <QObject>
#include <QThread>

class TestTh : public QObject
{
    Q_OBJECT
public:
    TestTh();
    virtual ~TestTh()=default;
public slots:
    void testSlot();
private:

    QObject* m_A{};
    QObject* m_B{};

};

#endif // TESTTH_H

test.cpp

#include "testth.h"
#include <QDebug>

TestTh::TestTh()
{

}

void TestTh::testSlot()
{
    auto d=new int[1000];
    delete []d;
    delete []d;
    qDebug()<<"test slot func";
}

In above code, the app will be crashed when I push the button. Beacuse, I double delete the array in the member testSlot. However, there is no any dump file generated. after some probe, I have been told that api MiniDumpWriteDump should be called in target process.Hence, I have some midification to my project, As showing in following section:

#include "mainwindow.h"

//#include <Windows.h>
#include <QApplication>
#include <QFile>
#include <QDeadlineTimer>
#include <QDebug>
#include <QSaveFile>
#include <QStringBuilder>
#include <QTextStream>
#include <mutex>
#include <QDateTime>

#include <QFileInfo>
//#include <minidumpapiset.h>
#include <io.h>
#include <QScopedPointer>
#include <QProcess>

auto WINAPI ExceptionHandler(LPEXCEPTION_POINTERS pException)->long
{
    QScopedPointer<QProcess> anotherExe{new QProcess()};
    anotherExe->setWorkingDirectory(qApp->applicationDirPath());
    anotherExe->setProgram(qApp->applicationDirPath() % QStringLiteral("/CrashDumpGuardor.exe"));

    auto pidPro=QString::number(GetCurrentProcessId());

    auto threadId=GetCurrentThreadId();

    char exceptionContent[32768];

    sprintf_s(exceptionContent,sizeof(exceptionContent)/sizeof (exceptionContent[0]),"%p",pException);

    anotherExe->setArguments(QStringList{pidPro,QString::number(threadId),QString::fromLatin1(exceptionContent),qApp->applicationDirPath()});
    anotherExe->start();
    anotherExe->waitForFinished();

    return TRUE;
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    SetUnhandledExceptionFilter(ExceptionHandler);

    MainWindow w;
    w.show();

    return a.exec();
}

for more details, I move the minidumpwritedump to another project named CrashDumpGuardor an that generate an exe named CrashDumpGuardor.exe that was placed on my crash app dir.I will create the sub process to call CrashDumpGuardor.exe with some argument. unfortunately, this method have any affect. there is no dump file generation.

after these attempations, I have tried with google breakpad in the

following section:
#include <QFileInfo>
#include <io.h>
#include <QScopedPointer>
#include <QProcess>
#include "breakpad/client/windows/handler/exception_handler.h"
using namespace google_breakpad;

static bool callback(const wchar_t *dump_path, const wchar_t *id,
    void *, EXCEPTION_POINTERS *,
    MDRawAssertionInfo *,
    bool succeeded) {
    if (succeeded)
        qWarning("Dump file created in %s, dump guid is %ws\n", dump_path, id);
    else
        qWarning("Dump failed\n");
    return succeeded;
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    ExceptionHandler eh(qApp->applicationDirPath().toStdWString().c_str(), NULL, callback, NULL,
                        ExceptionHandler::HANDLER_ALL);

    MainWindow w;
    w.show();

    return a.exec();
}

However, there is also no dump file generation, I'm really have no ideal to handle this problem, can someone give an assistance to me, Thanks!!!!


问:
GORM <nil> (\u003cnil\u003e) while Update database
```<code>if res = db.Save(&msg); res.Error != nil {
    log.Error(err)
    return
}
</code>```

I have simple code which is update column in database, but sometimes it gives me \u003cnil\u003e (<nil>) instead of nil.
Any reason or any experience who have ?

Body:
if res = db.Save(&msg); res.Error != nil {
    log.Error(err)
    return
}

I have simple code which is update column in database, but sometimes it gives me \u003cnil\u003e (<nil>) instead of nil.
Any reason or any experience who have ?


问:
allow null to "Date" type field encoded with DateAsLongEncoding
I need to allow default "null" value to Date type field.
Java class :

```<code>class Test{
@Nullable
@AvroEncode(using=DateAsLongEncoding.class)
private Date updatedDate;
}
</code>```

Generated schema for updatedDate:

```<code>{
 "name":"updatedDate",
  "type":{
      "type":"long",
      "CustomEncoding":"DateAsLongEncoding"
  }
}
</code>```

Whenever try to push the records to kafka it gives following exception whenever updatedDate is null

```<code>Caused by: java.lang.NullPointerException at org.apache.avro.reflect.DateAsLongEncoding.java
</code>```

How this field can be configured to nullable?

Body:
I need to allow default "null" value to Date type field.
Java class :

class Test{
@Nullable
@AvroEncode(using=DateAsLongEncoding.class)
private Date updatedDate;
}

Generated schema for updatedDate:

{
 "name":"updatedDate",
  "type":{
      "type":"long",
      "CustomEncoding":"DateAsLongEncoding"
  }
}

Whenever try to push the records to kafka it gives following exception whenever updatedDate is null

Caused by: java.lang.NullPointerException at org.apache.avro.reflect.DateAsLongEncoding.java

How this field can be configured to nullable?


问:
How to get a gooey effect with a lottie file?
I have created an animation in Aftereffects and using a filter I have added a gooey effect (link to the video below). Video files are very large so they can be negative for a website's performance. Therefore I like to use Lottie animations as a lightweight compromise where possible. From AE you can easily convert a composition into a JSON file which can be used as a Lottie animation. However, the gooey effect does not export into the Lottie file. How do I use a filter or some code to make the Lottie animation appear like the mp4 below?

Mp4 video the desired outcome: https://mango-media.eu/video/hero-01.mp4

I have tried adding a css filter to the parent container, but this does not work.

```<code><div style="filter: blur(10px) contrast(15);">
    <div id="lottie-blob-1">
    </div>
</div>

<script>
  var blob = bodymovin.loadAnimation({
    container: document.getElementById('lottie-blob-1'),
    renderer: 'svg',
    loop: true,
    autoplay: true,
    path: 'https://mango-media.eu/lottie/Hero-lottie-01.json'
  })
</script>
</code>```


问:
Hadoop mapreduce application failed due to OutOfMemoryError
I'm using Apache Druid to ingest data(type: index_hadoop), but the index task failed, there's no useful infomation in index log. Then I find the MR application(application name: OELandingType-determine_partitions_hashed-Optional.of([2022-12-25T00:00:00.000Z/20222-12-26T00:00:00.000Z], OELandingType is my druid datasource name)) was failed, the error in yarn log says:

```<code>2023-01-05 17:04:55,291 INFO [main] org.apache.hadoop.mapreduce.v2.app.job.impl.JobImpl: Adding job token for job_1672909107121_0001 to jobTokenSecretManager
2023-01-05 17:04:55,349 INFO [main] org.apache.hadoop.mapreduce.v2.app.job.impl.JobImpl: Not uberizing job_1672909107121_0001 because: too many reduces;
2023-01-05 17:04:55,397 INFO [main] org.apache.hadoop.mapreduce.v2.app.job.impl.JobImpl: Input size for job job_1672909107121_0001 = 115735. Number of splits = 1
2023-01-05 17:08:51,299 FATAL [main] org.apache.hadoop.mapreduce.v2.app.MRAppMaster: Error starting MRAppMaster
java.lang.OutOfMemoryError: GC overhead limit exceeded
    at java.util.concurrent.locks.ReentrantReadWriteLock.<init>(ReentrantReadWriteLock.java:240)
    at java.util.concurrent.locks.ReentrantReadWriteLock.<init>(ReentrantReadWriteLock.java:230)
    at org.apache.hadoop.mapreduce.v2.app.job.impl.TaskImpl.<init>(TaskImpl.java:304)
    at org.apache.hadoop.mapreduce.v2.app.job.impl.ReduceTaskImpl.<init>(ReduceTaskImpl.java:47)
    at org.apache.hadoop.mapreduce.v2.app.job.impl.JobImpl$InitTransition.createReduceTasks(JobImpl.java:1569)
    at org.apache.hadoop.mapreduce.v2.app.job.impl.JobImpl$InitTransition.transition(JobImpl.java:1494)
    at org.apache.hadoop.mapreduce.v2.app.job.impl.JobImpl$InitTransition.transition(JobImpl.java:1414)
    at org.apache.hadoop.yarn.state.StateMachineFactory$MultipleInternalArc.doTransition(StateMachineFactory.java:385)
    at org.apache.hadoop.yarn.state.StateMachineFactory.doTransition(StateMachineFactory.java:302)
    at org.apache.hadoop.yarn.state.StateMachineFactory.access$300(StateMachineFactory.java:46)
    at org.apache.hadoop.yarn.state.StateMachineFactory$InternalStateMachine.doTransition(StateMachineFactory.java:448)
    at org.apache.hadoop.mapreduce.v2.app.job.impl.JobImpl.handle(JobImpl.java:1008)
    at org.apache.hadoop.mapreduce.v2.app.job.impl.JobImpl.handle(JobImpl.java:139)
    at org.apache.hadoop.mapreduce.v2.app.MRAppMaster$JobEventDispatcher.handle(MRAppMaster.java:1436)
    at org.apache.hadoop.mapreduce.v2.app.MRAppMaster.serviceStart(MRAppMaster.java:1207)
    at org.apache.hadoop.service.AbstractService.start(AbstractService.java:193)
    at org.apache.hadoop.mapreduce.v2.app.MRAppMaster$5.run(MRAppMaster.java:1654)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:422)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1844)
    at org.apache.hadoop.mapreduce.v2.app.MRAppMaster.initAndStartAppMaster(MRAppMaster.java:1650)
    at org.apache.hadoop.mapreduce.v2.app.MRAppMaster.main(MRAppMaster.java:1583)
2023-01-05 17:09:05,108 INFO [main] org.apache.hadoop.util.ExitUtil: Exiting with status 1
2023-01-05 17:09:45,419 ERROR [Thread-0] org.apache.hadoop.yarn.YarnUncaughtExceptionHandler: Thread Thread[Thread-0,5,main] threw an Throwable, but we are shutting down, so ignoring this
java.lang.OutOfMemoryError: GC overhead limit exceeded
</code>```

You can see from the log the data size is quite small, Input size for job job_1672909107121_0001 = 115735. Number of splits = 1, following are some other information    which may be relevant:

Hadoop 2.8.5 based on yarn, total 4 x m5a.xlarge(4 Core 16G memory, 100G SSD GP3) , 3 were used as yarn node (12G Mem and 4 vCore)

yarn.app.mapreduce.am.resource.mb = 6144

yarn.app.mapreduce.am.command-opts = -Xmx4915m

mapreduce.map.memory.mb = 3072

mapreduce.reduce.memory.mb = 6144

Body:
I'm using Apache Druid to ingest data(type: index_hadoop), but the index task failed, there's no useful infomation in index log. Then I find the MR application(application name: OELandingType-determine_partitions_hashed-Optional.of([2022-12-25T00:00:00.000Z/20222-12-26T00:00:00.000Z], OELandingType is my druid datasource name)) was failed, the error in yarn log says:

2023-01-05 17:04:55,291 INFO [main] org.apache.hadoop.mapreduce.v2.app.job.impl.JobImpl: Adding job token for job_1672909107121_0001 to jobTokenSecretManager
2023-01-05 17:04:55,349 INFO [main] org.apache.hadoop.mapreduce.v2.app.job.impl.JobImpl: Not uberizing job_1672909107121_0001 because: too many reduces;
2023-01-05 17:04:55,397 INFO [main] org.apache.hadoop.mapreduce.v2.app.job.impl.JobImpl: Input size for job job_1672909107121_0001 = 115735. Number of splits = 1
2023-01-05 17:08:51,299 FATAL [main] org.apache.hadoop.mapreduce.v2.app.MRAppMaster: Error starting MRAppMaster
java.lang.OutOfMemoryError: GC overhead limit exceeded
    at java.util.concurrent.locks.ReentrantReadWriteLock.<init>(ReentrantReadWriteLock.java:240)
    at java.util.concurrent.locks.ReentrantReadWriteLock.<init>(ReentrantReadWriteLock.java:230)
    at org.apache.hadoop.mapreduce.v2.app.job.impl.TaskImpl.<init>(TaskImpl.java:304)
    at org.apache.hadoop.mapreduce.v2.app.job.impl.ReduceTaskImpl.<init>(ReduceTaskImpl.java:47)
    at org.apache.hadoop.mapreduce.v2.app.job.impl.JobImpl$InitTransition.createReduceTasks(JobImpl.java:1569)
    at org.apache.hadoop.mapreduce.v2.app.job.impl.JobImpl$InitTransition.transition(JobImpl.java:1494)
    at org.apache.hadoop.mapreduce.v2.app.job.impl.JobImpl$InitTransition.transition(JobImpl.java:1414)
    at org.apache.hadoop.yarn.state.StateMachineFactory$MultipleInternalArc.doTransition(StateMachineFactory.java:385)
    at org.apache.hadoop.yarn.state.StateMachineFactory.doTransition(StateMachineFactory.java:302)
    at org.apache.hadoop.yarn.state.StateMachineFactory.access$300(StateMachineFactory.java:46)
    at org.apache.hadoop.yarn.state.StateMachineFactory$InternalStateMachine.doTransition(StateMachineFactory.java:448)
    at org.apache.hadoop.mapreduce.v2.app.job.impl.JobImpl.handle(JobImpl.java:1008)
    at org.apache.hadoop.mapreduce.v2.app.job.impl.JobImpl.handle(JobImpl.java:139)
    at org.apache.hadoop.mapreduce.v2.app.MRAppMaster$JobEventDispatcher.handle(MRAppMaster.java:1436)
    at org.apache.hadoop.mapreduce.v2.app.MRAppMaster.serviceStart(MRAppMaster.java:1207)
    at org.apache.hadoop.service.AbstractService.start(AbstractService.java:193)
    at org.apache.hadoop.mapreduce.v2.app.MRAppMaster$5.run(MRAppMaster.java:1654)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:422)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1844)
    at org.apache.hadoop.mapreduce.v2.app.MRAppMaster.initAndStartAppMaster(MRAppMaster.java:1650)
    at org.apache.hadoop.mapreduce.v2.app.MRAppMaster.main(MRAppMaster.java:1583)
2023-01-05 17:09:05,108 INFO [main] org.apache.hadoop.util.ExitUtil: Exiting with status 1
2023-01-05 17:09:45,419 ERROR [Thread-0] org.apache.hadoop.yarn.YarnUncaughtExceptionHandler: Thread Thread[Thread-0,5,main] threw an Throwable, but we are shutting down, so ignoring this
java.lang.OutOfMemoryError: GC overhead limit exceeded

You can see from the log the data size is quite small, Input size for job job_1672909107121_0001 = 115735. Number of splits = 1, following are some other information    which may be relevant:

Hadoop 2.8.5 based on yarn, total 4 x m5a.xlarge(4 Core 16G memory, 100G SSD GP3) , 3 were used as yarn node (12G Mem and 4 vCore)

yarn.app.mapreduce.am.resource.mb = 6144

yarn.app.mapreduce.am.command-opts = -Xmx4915m

mapreduce.map.memory.mb = 3072

mapreduce.reduce.memory.mb = 6144


问:
LINQ to SQL one to one relation anomaly
I am a bit confused by the behaviour of LINQ To SQL (just for clarity I do not mean EntiyFramework or LINQ To Entity but old LINQ To SQL).

I have a relation between Entity and Resources. Entities are subject of my code (for example people) and resources are things used by entities (for example documents).
To map the relation I use a cross join table EntityResource and the Resource table.

When I need to refresh the resources associated to an Entity I delete all record form the cross join table (ResourceEntity) for a given Entity, then scan the Entity and search to see if for each Resource in the Entity if there is already an item in Resource table (resources may be shared among many entities).
If the Resource exist I just recreate the relation, otherwise first I create the Resource and then the relation.
Finally I delete all Resource that have no Entity association through the EntityResource cross join table.

My problem arises in the phase of association rebuilding, when I scan an Entity to re-associate existing Resource

```<code>foreach (var candidareResource in candidateResources) //set of resources for a given entity
{
    tbl_res_ResourcesEntity relation = new tbl_res_ResourcesEntity() //cross join table rebuild from a specific entity_id (already deleted here i just rebuild it)
    {
        ENTITY_ID       = entity.Id,
        ENTITY_TYPE_ID  = (int)entity.EType,
        ID_LANG         = candidareResource.ID_LANG,
        //navigation to Resource (1,1) relation is NULL by now
    };

    repository.Create(relation);
    //create is almost context.tbl_res_ResourcesEntities.InsertOnSubmit(relation);

    context.SubmitChanges();

    repository.AttachResource(relation, candidareResource);
    context.SubmitChanges();
}
</code>```

AttachResource basically check that the resource I try to create does not exist, if it exists create only association, otherwise create the resource and then the association, here the code:

```<code>public virtual tbl_res_ResourcesEntity AttachResource (tbl_res_ResourcesEntity objToUpdate, tbl_res_Resource resourceToAttach)
{
    base.Update(objToUpdate);

    if ( objToUpdate.ID <= 0)
        throw new ExtendedArgumentException("resourceToAttach", "No valid resource");

    var dbObjectToUpdate = this.Datacontext.tbl_res_ResourcesEntities.FirstOrDefault(res => res.ID == objToUpdate.ID);
    var dbResource = this.Datacontext.tbl_res_Resources.FirstOrDefault(res => res.RESOURCE_KEY == resourceToAttach.RESOURCE_KEY && res.RESOURCE_TYPE == resourceToAttach.RESOURCE_TYPE);

    if (dbResource == null) //always false in my testing scenario
    {
        dbResource = resourceToAttach;
        dbResource.SanifyLinqEntity();

        this.Datacontext.tbl_res_Resources.InsertOnSubmit(dbResource);
    }

    dbObjectToUpdate.Resource = dbResource;

    return dbObjectToUpdate;
}
</code>```

In my scenario the Resources always exist so ignore the (dbResource == null)

Here is how the ORM show entity relation :

The issue arise when the same resource, is used many times by an Entity. This may happen if I would attach a document (Eg : a pdf file) twice. It's a bit strange, but document are attached in a language, so if entity request it in a specific language I have localization. But sometimes you don't have a localized document (eg : a PDF in English meant to be viewed also for the French language) and so the same resource end up to be attached twice. This is not an issue because document is stored only once, the "link" is doubled

So I get my PDF doubled

Resource

ID
ID_LANG
RES_KEY
RES_TYPE

1
en
document.pdf
pdf

ResourceEntity (cross join table)

ID
ENTITY_ID
ENTITY_TYPE
RESOURCE_ID
RESOURCE_TYPE
ID_LANG

1
1
Person
1
pdf
en

2
1
Person
1
pdf
fr

Entity

ID
NAME
TYPE

1
John Smith
Person

Problem is, if I try to attach the same Resource more than once (to the same entity), I got an error:

An attempt was made to remove a relationship between a tbl_res_Resource and a tbl_res_ResourcesEntity. However, one of the relationship's foreign keys (tbl_res_ResourcesEntity.RESOURCE_ID, tbl_res_ResourcesEntity.RESOURCE_TYPE_ID) cannot be set to null.

Not clear why I am seeing that behaviour.

Title: LINQ to SQL one to one relation anomaly

Body:
I am a bit confused by the behaviour of LINQ To SQL (just for clarity I do not mean EntiyFramework or LINQ To Entity but old LINQ To SQL).

I have a relation between Entity and Resources. Entities are subject of my code (for example people) and resources are things used by entities (for example documents).
To map the relation I use a cross join table EntityResource and the Resource table.

When I need to refresh the resources associated to an Entity I delete all record form the cross join table (ResourceEntity) for a given Entity, then scan the Entity and search to see if for each Resource in the Entity if there is already an item in Resource table (resources may be shared among many entities).
If the Resource exist I just recreate the relation, otherwise first I create the Resource and then the relation.
Finally I delete all Resource that have no Entity association through the EntityResource cross join table.

My problem arises in the phase of association rebuilding, when I scan an Entity to re-associate existing Resource

foreach (var candidareResource in candidateResources) //set of resources for a given entity
{
    tbl_res_ResourcesEntity relation = new tbl_res_ResourcesEntity() //cross join table rebuild from a specific entity_id (already deleted here i just rebuild it)
    {
        ENTITY_ID       = entity.Id,
        ENTITY_TYPE_ID  = (int)entity.EType,
        ID_LANG         = candidareResource.ID_LANG,
        //navigation to Resource (1,1) relation is NULL by now
    };

    repository.Create(relation);
    //create is almost context.tbl_res_ResourcesEntities.InsertOnSubmit(relation);

    context.SubmitChanges();

    repository.AttachResource(relation, candidareResource);
    context.SubmitChanges();
}

AttachResource basically check that the resource I try to create does not exist, if it exists create only association, otherwise create the resource and then the association, here the code:

public virtual tbl_res_ResourcesEntity AttachResource (tbl_res_ResourcesEntity objToUpdate, tbl_res_Resource resourceToAttach)
{
    base.Update(objToUpdate);

    if ( objToUpdate.ID <= 0)
        throw new ExtendedArgumentException("resourceToAttach", "No valid resource");

    var dbObjectToUpdate = this.Datacontext.tbl_res_ResourcesEntities.FirstOrDefault(res => res.ID == objToUpdate.ID);
    var dbResource = this.Datacontext.tbl_res_Resources.FirstOrDefault(res => res.RESOURCE_KEY == resourceToAttach.RESOURCE_KEY && res.RESOURCE_TYPE == resourceToAttach.RESOURCE_TYPE);

    if (dbResource == null) //always false in my testing scenario
    {
        dbResource = resourceToAttach;
        dbResource.SanifyLinqEntity();

        this.Datacontext.tbl_res_Resources.InsertOnSubmit(dbResource);
    }

    dbObjectToUpdate.Resource = dbResource;

    return dbObjectToUpdate;
}

In my scenario the Resources always exist so ignore the (dbResource == null)

Here is how the ORM show entity relation :

The issue arise when the same resource, is used many times by an Entity. This may happen if I would attach a document (Eg : a pdf file) twice. It's a bit strange, but document are attached in a language, so if entity request it in a specific language I have localization. But sometimes you don't have a localized document (eg : a PDF in English meant to be viewed also for the French language) and so the same resource end up to be attached twice. This is not an issue because document is stored only once, the "link" is doubled

So I get my PDF doubled

Resource

ID
ID_LANG
RES_KEY
RES_TYPE

1
en
document.pdf
pdf

ResourceEntity (cross join table)

ID
ENTITY_ID
ENTITY_TYPE
RESOURCE_ID
RESOURCE_TYPE
ID_LANG

1
1
Person
1
pdf
en

2
1
Person
1
pdf
fr

Entity

ID
NAME
TYPE

1
John Smith
Person

Problem is, if I try to attach the same Resource more than once (to the same entity), I got an error:

An attempt was made to remove a relationship between a tbl_res_Resource and a tbl_res_ResourcesEntity. However, one of the relationship's foreign keys (tbl_res_ResourcesEntity.RESOURCE_ID, tbl_res_ResourcesEntity.RESOURCE_TYPE_ID) cannot be set to null.

Not clear why I am seeing that behaviour.


问:
Type handler implementation for array of objects in myBatis
I am trying to write type handler for array of objects but this is giving me errors. I want to store arraylist as JSON in DB(mysql) and retrieve it as arraylist . I got the type handler examples with arraylist of String but here I am using custom class instead of String and not able to understand what is the correct way to write type handler for it.

Here is the code for typeHandler

```<code>  import com.knimbus.model.Options;

  import org.apache.ibatis.type.BaseTypeHandler;
  import org.apache.ibatis.type.JdbcType;
  import org.apache.ibatis.type.MappedJdbcTypes;

  import java.sql.Array;
  import java.sql.CallableStatement;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import java.util.List;

  import com.google.common.collect.Lists;

    @MappedJdbcTypes(JdbcType.VARCHAR)
    public class MyBatisJsonTypeHandler extends BaseTypeHandler<List<Options>> {

@Override
  public void setNonNullParameter(PreparedStatement ps, int i, List<Options> parameter, JdbcType              jdbcType) throws SQLException {
    Array array = ps.getConnection().createArrayOf("text", parameter.toArray());
    ps.setArray(i, array);
  }

  @Override
  public List<Options> getNullableResult(ResultSet rs, String columnName) throws SQLException {
    return toList(rs.getArray(columnName));
  }

  @Override
  public List<Options> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
    return toList(rs.getArray(columnIndex));
  }

  @Override
      public List<Options> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException       {
    return toList(cs.getArray(columnIndex));
  }

      private List<Options> toList(Array pgArray) throws SQLException {
        if (pgArray == null) return Lists.newArrayList();

           Options[] options = (Options[]) pgArray.getArray();
           return containsOnlyNulls(options) ? Lists.<Options>newArrayList() :           Lists.newArrayList(options);
}

  private boolean containsOnlyNulls(Options[] options) {
    for (Options ops : options) {
      if (ops != null) {
        return false;
      }
    }
    return true;
  }}`
</code>```

My dto class looks like this

```<code>import java.util.ArrayList;
import java.util.List;

public class Question {
private Long questionId;
private String question;

private  List<Options> options = new ArrayList<Options>();

public Question() {

}

public Long getQuestionId() {
    return questionId;
}

public void setQuestionId(Long questionId) {
    this.questionId = questionId;
}

public String getQuestion() {
    return question;
}

public void setQuestion(String question) {
    this.question = question;
}

      public List<Options> getOptions() {
    return options;
}

    public void setOptions(List<Options> options) {
    this.options = options;
}
</code>```

}

```<code>     public class Options {
     private String optionCode;
     private String optionName;
     private int order;
     public Options() {}
     public String getOptionCode() {
        return optionCode;
}
    public void setOptionCode(String optionCode) {
    this.optionCode = optionCode;
}
    public String getOptionName() {
    return optionName;
}
       public void setOptionName(String optionName) {
this.optionName = optionName;
}
    public int getOrder() {
    return order;
}
     public void setOrder(int order) {
    this.order = order;
}
    @Override
    public String toString() {
    return "Options [optionCode=" + optionCode + ", optionName=" + optionName + ", order=" +         order + "]";
}

  }
</code>```

`

my mapper file code is like this

`

```<code></resultMap>
    <select id="getAllQuestion" resultType="question" >
    SELECT * FROM question
    </select>

    <insert id="addQuestion" parameterType="question">
    INSERT INTO question( questionId, question, options)
    VALUES(#{questionId},#{question}, #{options, typeHandler=
    {com.knimbus.util.config.MyBatisJsonTypeHandler}, javaType =
      {com.knimbus.model.Options}})
       </insert>
</code>```

Below is the request data passing through client

```<code>   {
    "questionId": 4,
      "question":"Who will win FIFA world cup?",
    "options": [
    {
        "optionCode": "A",
        "optionName": "Brazil",
        "order": 1
    },
    {
        "optionCode": "B",
        "optionName": "France",
        "order": 2
    },
    {
        "optionCode": "C",
        "optionName": "Argentina",
        "order": 3
    }
     ]
      }
</code>```

below is the table structure

```<code> ` CREATE TABLE `question`(
  `questionId` int NOT NULL AUTO_INCREMENT,
  `question` varchar(50) NOT NULL,
  `Options` json DEFAULT NULL,
  PRIMARY KEY (`questionId`));`
</code>```

While inserting the data getting below errors. Looks like I am missing something in type handler class but not able to figure it out.

SEVERE: Servlet.service() for servlet [spring] in context with path [/UserMyBatis] threw exception [Request processing failed; nested exception is org.apache.ibatis.exceptions.PersistenceException:

Error updating database.  Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias '{com.knimbus.util.config.MyBatisJsonTypeHandler'.  Cause: java.lang.ClassNotFoundException: Cannot find class: {com.knimbus.util.config.MyBatisJsonTypeHandler

Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias '{com.knimbus.util.config.MyBatisJsonTypeHandler'.  Cause: java.lang.ClassNotFoundException: Cannot find class: {com.knimbus.util.config.MyBatisJsonTypeHandler] with root cause

java.lang.ClassNotFoundException: Cannot find class: {com.knimbus.util.config.MyBatisJsonTypeHandler

and while retrieving data it does not send the "options" class related data, something like below

```<code>   `[
    {
    "questionId": 3,
    "question": "Who will win FIFA world cup ",
    "options": []
     }
     ]`
</code>```

Body:
I am trying to write type handler for array of objects but this is giving me errors. I want to store arraylist as JSON in DB(mysql) and retrieve it as arraylist . I got the type handler examples with arraylist of String but here I am using custom class instead of String and not able to understand what is the correct way to write type handler for it.

Here is the code for typeHandler

  import com.knimbus.model.Options;

  import org.apache.ibatis.type.BaseTypeHandler;
  import org.apache.ibatis.type.JdbcType;
  import org.apache.ibatis.type.MappedJdbcTypes;

  import java.sql.Array;
  import java.sql.CallableStatement;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import java.util.List;

  import com.google.common.collect.Lists;

    @MappedJdbcTypes(JdbcType.VARCHAR)
    public class MyBatisJsonTypeHandler extends BaseTypeHandler<List<Options>> {

@Override
  public void setNonNullParameter(PreparedStatement ps, int i, List<Options> parameter, JdbcType              jdbcType) throws SQLException {
    Array array = ps.getConnection().createArrayOf("text", parameter.toArray());
    ps.setArray(i, array);
  }

  @Override
  public List<Options> getNullableResult(ResultSet rs, String columnName) throws SQLException {
    return toList(rs.getArray(columnName));
  }

  @Override
  public List<Options> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
    return toList(rs.getArray(columnIndex));
  }

  @Override
      public List<Options> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException       {
    return toList(cs.getArray(columnIndex));
  }

      private List<Options> toList(Array pgArray) throws SQLException {
        if (pgArray == null) return Lists.newArrayList();

           Options[] options = (Options[]) pgArray.getArray();
           return containsOnlyNulls(options) ? Lists.<Options>newArrayList() :           Lists.newArrayList(options);
}

  private boolean containsOnlyNulls(Options[] options) {
    for (Options ops : options) {
      if (ops != null) {
        return false;
      }
    }
    return true;
  }}`

My dto class looks like this

import java.util.ArrayList;
import java.util.List;

public class Question {
private Long questionId;
private String question;

private  List<Options> options = new ArrayList<Options>();

public Question() {

}

public Long getQuestionId() {
    return questionId;
}

public void setQuestionId(Long questionId) {
    this.questionId = questionId;
}

public String getQuestion() {
    return question;
}

public void setQuestion(String question) {
    this.question = question;
}

      public List<Options> getOptions() {
    return options;
}

    public void setOptions(List<Options> options) {
    this.options = options;
}

}

     public class Options {
     private String optionCode;
     private String optionName;
     private int order;
     public Options() {}
     public String getOptionCode() {
        return optionCode;
}
    public void setOptionCode(String optionCode) {
    this.optionCode = optionCode;
}
    public String getOptionName() {
    return optionName;
}
       public void setOptionName(String optionName) {
this.optionName = optionName;
}
    public int getOrder() {
    return order;
}
     public void setOrder(int order) {
    this.order = order;
}
    @Override
    public String toString() {
    return "Options [optionCode=" + optionCode + ", optionName=" + optionName + ", order=" +         order + "]";
}

  }

`

my mapper file code is like this

`

</resultMap>
    <select id="getAllQuestion" resultType="question" >
    SELECT * FROM question
    </select>

    <insert id="addQuestion" parameterType="question">
    INSERT INTO question( questionId, question, options)
    VALUES(#{questionId},#{question}, #{options, typeHandler=
    {com.knimbus.util.config.MyBatisJsonTypeHandler}, javaType =
      {com.knimbus.model.Options}})
       </insert>

Below is the request data passing through client

   {
    "questionId": 4,
      "question":"Who will win FIFA world cup?",
    "options": [
    {
        "optionCode": "A",
        "optionName": "Brazil",
        "order": 1
    },
    {
        "optionCode": "B",
        "optionName": "France",
        "order": 2
    },
    {
        "optionCode": "C",
        "optionName": "Argentina",
        "order": 3
    }
     ]
      }

below is the table structure

 ` CREATE TABLE `question`(
  `questionId` int NOT NULL AUTO_INCREMENT,
  `question` varchar(50) NOT NULL,
  `Options` json DEFAULT NULL,
  PRIMARY KEY (`questionId`));`

While inserting the data getting below errors. Looks like I am missing something in type handler class but not able to figure it out.

SEVERE: Servlet.service() for servlet [spring] in context with path [/UserMyBatis] threw exception [Request processing failed; nested exception is org.apache.ibatis.exceptions.PersistenceException:

Error updating database.  Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias '{com.knimbus.util.config.MyBatisJsonTypeHandler'.  Cause: java.lang.ClassNotFoundException: Cannot find class: {com.knimbus.util.config.MyBatisJsonTypeHandler

Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias '{com.knimbus.util.config.MyBatisJsonTypeHandler'.  Cause: java.lang.ClassNotFoundException: Cannot find class: {com.knimbus.util.config.MyBatisJsonTypeHandler] with root cause

java.lang.ClassNotFoundException: Cannot find class: {com.knimbus.util.config.MyBatisJsonTypeHandler

and while retrieving data it does not send the "options" class related data, something like below

   `[
    {
    "questionId": 3,
    "question": "Who will win FIFA world cup ",
    "options": []
     }
     ]`